All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Benato <denis.benato@linux.dev>
To: Paolo Pisati <p.pisati@gmail.com>, Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>
Cc: "Joshua Leivenzon" <hacker1024@users.sourceforge.net>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Luke Jones" <luke@ljones.dev>, "Ivan Levchenko" <me@livan.pro>,
	"Rebecca Mara Müller" <rebecca.mara@posteo.de>,
	"Nathan Chancellor" <nathan@kernel.org>
Subject: Re: [PATCH v3 1/7] HID: asus: Fix up Zenbook Duo report descriptors
Date: Sun, 18 Oct 2026 17:50:08 +0200	[thread overview]
Message-ID: <b22a521d-ec6e-4ac8-9aaa-d34e67ba898f@linux.dev> (raw)
In-Reply-To: <20261013104033.36079-2-p.pisati@gmail.com>


On 10/13/26 12:39, Paolo Pisati wrote:
> From: Joshua Leivenzon <hacker1024@users.sourceforge.net>
>
> The Zenbook Duo keyboards (UX8406MA, UX8406CA, UX8407AA) ship the same
> broken vendor hotkey collection as the T100CHI/T90CHI keyboard docks:
> the Input item of report 0x5a is preceded by a single Usage (76h)
> instead of a Usage Minimum/Maximum range, so none of the hotkey codes
> get mapped and every key press logs
>
>   Unmapped Asus vendor usagepage code 0x76
>
> Extend the T100CHI/T90CHI fixup to the Zenbook Duo: the descriptor is
> 90 bytes long with the bogus usage at offset 66 on the USB hotkey
> interface, and 257 bytes long with the usage at offset 176 over
> Bluetooth.
>
> The dock fixup only moves the 12 bytes between the usage and the End
> Collection item, as nothing but a bogus trailing 0 byte follows them.
> That is not true of the Zenbook Duo: the collection goes on with a 15
> byte feature report (also ID 0x5a) after the Input item, and over
> Bluetooth a further collection follows it, which a 12 byte move
> corrupts, leaving stray 0 bytes at the end. Move everything after the
> usage instead, after dropping any trailing 0 bytes, and allocate the
> two bytes the usage range adds. The result for the T100CHI/T90CHI is
> unchanged.
>
> Signed-off-by: Joshua Leivenzon <hacker1024@users.sourceforge.net>
> [pisati: fold the USB offsets and the padding removal into this patch,
>  bound the padding removal, move the whole tail of the descriptor, and
>  end the branch chain with a plain else so clang does not warn that
>  rsize_orig may be uninitialized]
> Assisted-by: LLM
> Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
> Tested-by: Rebecca Mara Müller <rebecca.mara@posteo.de> # UX8407AA

Hello Paolo,

I am back from vacation and I can therefore getting on with my review.

I don't know if I have enough time for all patches but I will try!

Thanks for looking into these devices!

> ---
>  drivers/hid/hid-asus.c | 38 ++++++++++++++++++++++++++------------
>  1 file changed, 26 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> index bd46aba6622a..34739198d90e 100644
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c
> @@ -100,6 +100,7 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
>  #define QUIRK_ROG_ALLY_XPAD		BIT(13)
>  #define QUIRK_HID_FN_LOCK		BIT(14)
>  #define QUIRK_FILTER_CAMERA_COMPANION	BIT(15)
> +#define QUIRK_ZENBOOK_DUO_KEYBOARD	BIT(16)
>  
>  #define I2C_KEYBOARD_QUIRKS			(QUIRK_FIX_NOTEBOOK_REPORT | \
>  						 QUIRK_NO_INIT_REPORTS | \
> @@ -1579,43 +1580,56 @@ static const __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
>  		hid_info(hdev, "Fixing up Asus T100 keyb report descriptor\n");
>  		rdesc[74] &= ~HID_MAIN_ITEM_CONSTANT;
>  	}
> -	/* For the T100CHI/T90CHI keyboard dock */
> -	if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI)) {
> +	/* For the T100CHI/T90CHI keyboard dock and Zenbook Duo keyboards */
> +	if (drvdata->quirks & (QUIRK_T100CHI | QUIRK_T90CHI | QUIRK_ZENBOOK_DUO_KEYBOARD)) {
>  		int rsize_orig;
>  		int offs;
>  
>  		if (drvdata->quirks & QUIRK_T100CHI) {
>  			rsize_orig = 403;
>  			offs = 388;
> -		} else {
> +		} else if (drvdata->quirks & QUIRK_T90CHI) {
>  			rsize_orig = 306;
>  			offs = 291;
> +		} else if (hid_is_usb(hdev)) { /* QUIRK_ZENBOOK_DUO_KEYBOARD */
> +			rsize_orig = 90;
> +			offs = 66;
> +		} else { /* QUIRK_ZENBOOK_DUO_KEYBOARD over Bluetooth */
> +			rsize_orig = 257;
> +			offs = 176;
>  		}

Please either use a switch or otherwise make each if check one quirk, eventually use other nested if(s)
to check for bluetooth in order to not cause future problems if this code needs adding other models.

Also unless it's for counting try to use explicit types matching what you are trying to do like u8 or u16 etc...

>  
>  		/*
>  		 * Change Usage (76h) to Usage Minimum (00h), Usage Maximum
> -		 * (FFh) and clear the flags in the Input() byte.
> -		 * Note the descriptor has a bogus 0 byte at the end so we
> -		 * only need 1 extra byte.
> +		 * (FFh) and clear the flags in the Input() byte, shifting
> +		 * the rest of the descriptor by the 2 bytes that adds. Drop
> +		 * the bogus 0 bytes some descriptors end with first, but
> +		 * never the Input() item that follows the usage.
>  		 */
>  		if (*rsize == rsize_orig &&
>  			rdesc[offs] == 0x09 && rdesc[offs + 1] == 0x76) {
> +			unsigned int new_rsize = rsize_orig;

In kernel declaration of variables goes on top of the function, in reverse xmas-tree.

The only exception is with _kfree() pattern for pointers.

>  			__u8 *new_rdesc;
>  
> -			new_rdesc = devm_kzalloc(&hdev->dev, rsize_orig + 1,
> +			while (new_rsize > offs + 14 && rdesc[new_rsize - 1] == 0)
> +				--new_rsize;
> +
> +			new_rdesc = devm_kzalloc(&hdev->dev, new_rsize + 2,
>  						 GFP_KERNEL);
>  			if (!new_rdesc)
>  				return rdesc;
>  
>  			hid_info(hdev, "Fixing up %s keyb report descriptor\n",
> -				drvdata->quirks & QUIRK_T100CHI ?
> -				"T100CHI" : "T90CHI");
> +				drvdata->quirks & QUIRK_T100CHI ? "T100CHI" :
> +				drvdata->quirks & QUIRK_T90CHI ? "T90CHI" :
> +				"Zenbook Duo");
>  

Does the zenbook duo really needs fixing the report descriptor? I think you can avoid this
altogether on this hardware.

Best regards,
Denis Benato

> -			memcpy(new_rdesc, rdesc, rsize_orig);
> -			*rsize = rsize_orig + 1;
> +			memcpy(new_rdesc, rdesc, new_rsize);
> +			*rsize = new_rsize + 2;
>  			rdesc = new_rdesc;
>  
> -			memmove(rdesc + offs + 4, rdesc + offs + 2, 12);
> +			memmove(rdesc + offs + 4, rdesc + offs + 2,
> +				new_rsize - (offs + 2));
>  			rdesc[offs] = 0x19;
>  			rdesc[offs + 1] = 0x00;
>  			rdesc[offs + 2] = 0x29;

  reply	other threads:[~2026-10-18 15:50 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 10:39 [PATCH v3 0/7] HID: asus: ASUS Zenbook Duo keyboard support Paolo Pisati
2026-10-13 10:39 ` [PATCH v3 1/7] HID: asus: Fix up Zenbook Duo report descriptors Paolo Pisati
2026-10-18 15:50   ` Denis Benato [this message]
2026-10-18 16:18     ` Rebecca Mara Müller
2026-10-18 17:52       ` Denis Benato
2026-10-13 10:39 ` [PATCH v3 2/7] HID: asus: Add missing Zenbook Duo hotkeys Paolo Pisati
2026-10-18 15:55   ` Denis Benato
2026-10-18 21:38     ` Nathan Chancellor
2026-10-18 21:39       ` Denis Benato
2026-10-13 10:40 ` [PATCH v3 3/7] HID: asus: Force hid-input to bind to the Zenbook Duo hotkey interface Paolo Pisati
2026-10-18 16:06   ` Denis Benato
2026-10-13 10:40 ` [PATCH v3 4/7] HID: asus: Cycle the platform profile from the Zenbook Duo profile key Paolo Pisati
2026-10-18 16:27   ` Denis Benato
2026-10-13 10:40 ` [PATCH v3 5/7] HID: asus: Do not send feature reports larger than declared Paolo Pisati
2026-10-18 16:52   ` Denis Benato
2026-10-13 10:40 ` [PATCH v3 6/7] HID: asus: add prod-id, quirk for Zenbook Duo keyboard Paolo Pisati
2026-10-18 16:57   ` Denis Benato
2026-10-18 21:43     ` Nathan Chancellor
2026-10-18 21:46       ` Denis Benato
2026-10-13 10:40 ` [PATCH v3 7/7] HID: asus: Re-send the Zenbook Duo keyboard handshake after probe Paolo Pisati
2026-10-18 17:10   ` Denis Benato
2026-10-18 19:18     ` Rebecca Mara Müller
2026-10-18 19:48       ` Denis Benato
2026-10-19  6:12         ` Rebecca Mara Müller
2026-10-19 11:03           ` Denis Benato
2026-10-13 11:45 ` [PATCH v3 0/7] HID: asus: ASUS Zenbook Duo keyboard support Rebecca Mara Müller
2026-10-13 13:56   ` Denis Benato
2026-10-14 13:21     ` Paolo Pisati
2026-10-18 17:21       ` Denis Benato

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b22a521d-ec6e-4ac8-9aaa-d34e67ba898f@linux.dev \
    --to=denis.benato@linux.dev \
    --cc=bentiss@kernel.org \
    --cc=hacker1024@users.sourceforge.net \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luke@ljones.dev \
    --cc=me@livan.pro \
    --cc=nathan@kernel.org \
    --cc=p.pisati@gmail.com \
    --cc=rebecca.mara@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.