From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796151752; b=Yer+cJe2OrgHUoZLty9cJEy3rQRlnlUzol7A+Zh1AV4q3U7Fa+z8dJczWn6BqUZDS0bA wxsqjjsNfP021ujjxjOaL6vflyPHS9btItFjdfs76f4eGxa3kbxt0MyrGTmW6UjcINmu4 My6zUp9Jen7tWiq/9Q9ozCM2stYibTcznaqQQr9gThr9zjvNC5GWec88u9kewoNpGgrso PZNKkeTJHJwvEj/Ezm+loX2evBbiYlwNeVIr06M4U9jB9rvJCqt3DQMc4lBL8p2UvyTpJ W1mpHrCPR+QXqf+skMpQuwDaPoeh4OCKUoEos5N31ztRHHV1J4kDth/Yg7lv2y8y8Xg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796151752; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=+VPjhFGMyF7XawBKXOerZSvyyG7US8TvGUfJIHJV/P0=; b=AjPJj5ZF562ur+BgrlPis0HDITg3MNOdyqfFjGjtksJh7GSK6yzGIMOE+YJRMqAaMTy7 PmZMAOHugCJp4MqhCEN2R1Qc9xULPSnKtlwaVqaxkO726CbqLWRExBDjMZlyoqBpka0/U lk2I8/VSd2m40oMpbOXsOfetARBycwF/J3TQ7HIudlhKPZtSvpUHx7wvmXv0o7pH2mnU8 ged9n32LpDbAMvWiILYDDqSN+fTZyjZBy+mKM3GJ0GKAdJsLyRZbi5L1l33BY0+ACBGM4 xNi1S53ZP2ZTFxka6BWWPL5wqGU30CFTyEsrgD3pgDhFY6Zl7AP582/bjacmydrm4aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=idksJnxh; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B123606A31A for ; Tue, 1 Dec 2026 19:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=idksJnxh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D7B41F00926; Tue, 1 Dec 2026 19:02:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796151751; bh=+VPjhFGMyF7XawBKXOerZSvyyG7US8TvGUfJIHJV/P0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=idksJnxhH+MbK2HEMwMxGznV8MuH2U4B1yoDrFZWNpPq8m2xprCOAynfB2GjGT4QJ k7G+TwJUhGFg2zqZL8zgeJcse2TSLvyWWFjef6idgcwDa5ksIoP2DzNkc4Dqs/X/MH TmsNAQEPf5SGFLmq4kCwYtVnsXJZ1X1mZIDGukxkGA1N6aOblZf0W+UgURQrJgkQ9N wN+oYg0+b3rio0dX4EKjh34mDWElZOzOSBRG19Br1U2usoKOVgL/wzUKZxwxfAj8bD h8QfBOLBHWpBsnGiJxJB73xKEg3TsGAiUznnzOm8WlTnTU5vHur+eeDQf08bjWu7iQ UgvfDRY3LoeTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] HID: asus: support the Zenbook A14 (UX3407RA) keyboard backlight Reply-To: sashiko-reviews@lists.linux.dev To: "Jesper B. Christensen" Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261201185118.342672-1-jaytersen@gmail.com> References: <20261201185118.342672-1-jaytersen@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 19:02:30 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] HID: asus: always-true QUIRK_KBD_REPORT_SIZE check in asus_kbd_set_report() - [High] HID: asus: sleep in atomic context in asus_kbd_set_brightness_cdev() - [Medium] HID: asus: unconsumed KEY_KBDILLUMTOGGLE and LED desync in asus_event() - [Medium] HID: asus: error fallthrough and LED init order in asus_kbd_register_leds() - [Medium] HID: asus: teardown race on kbd_led_cdev in asus_remove() and asus_probe() - [Medium] HID: asus: unsynchronized kbd_backlight_brightness updates across LED paths -- commit 88e8e96de263e1806c05ad0eaf08fe87ba34473c Author: Jesper B. Christensen HID: asus: support the Zenbook A14 (UX3407RA) keyboard backlight This commit adds HID device ID 0B05:0220 for the ASUS Zenbook A14 (UX3407RA) I2C keyboard, introduces QUIRK_KBD_REPORT_SIZE and QUIRK_KBD_OOBE, and registers a direct LED class device for the keyboard backlight when asus-wmi is unavailable. > diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c > index 4f5749c9b2dbb..1e940a495c41c 100644 > --- a/drivers/hid/hid-asus.c > +++ b/drivers/hid/hid-asus.c [ ... ] > @@ -477,6 +482,7 @@ static int asus_event(struct hid_device *hdev, struct= hid_field *field, > case KEY_KBDILLUMDOWN: > return !asus_hid_event(ASUS_EV_BRTDOWN); > case KEY_KBDILLUMTOGGLE: > + asus_kbd_illum_toggle(drvdata); > return !asus_hid_event(ASUS_EV_BRTTOGGLE); > case KEY_FN_ESC: > if (drvdata->quirks & QUIRK_HID_FN_LOCK) { [Severity: Medium] Does KEY_KBDILLUMTOGGLE both toggle the backlight in the kernel and get forwarded to userspace when asus-wmi is absent? When asus-wmi is unavailable, asus_hid_event(ASUS_EV_BRTTOGGLE) returns -ENODEV, so !asus_hid_event() returns 0 and hid_process_event() reports KEY_KBDILLUMTOGGLE to userspace after asus_kbd_illum_toggle() has already advanced the hardware brightness. In addition, asus_kbd_illum_toggle() does not update drvdata->kbd_led_cdev.brightness or notify userspace via led_classdev_notify_brightness_hw_changed(), so a userspace power daemon handling the key event will toggle sysfs a second time from a stale brightness value. > @@ -585,10 +591,18 @@ static int asus_raw_event(struct hid_device *hdev, > static int asus_kbd_set_report(struct hid_device *hdev, const u8 *buf, s= ize_t buf_size) > { > int ret; > - u8 *dmabuf __free(kfree) =3D kmemdup(buf, buf_size, GFP_KERNEL); > + size_t alloc_size =3D buf_size; > + > + if (QUIRK_KBD_REPORT_SIZE) > + alloc_size =3D (buf_size > FEATURE_KBD_REPORT_SIZE) ? > + buf_size : FEATURE_KBD_REPORT_SIZE; > + > + u8 *dmabuf __free(kfree) =3D kzalloc(alloc_size, GFP_KERNEL); > if (!dmabuf) > return -ENOMEM; > =20 > + memcpy(dmabuf, buf, buf_size); > + > /* The device may be runtime suspended, e.g. for a deferred backlight c= hange */ > ret =3D hid_hw_power(hdev, PM_HINT_FULLON); > if (ret < 0) > @@ -598,8 +612,8 @@ static int asus_kbd_set_report(struct hid_device *hde= v, const u8 *buf, size_t bu > * The report ID should be set from the incoming buffer due to LED and = key > * interfaces having different pages > */ > - ret =3D hid_hw_raw_request(hdev, buf[0], dmabuf, buf_size, HID_FEATURE_= REPORT, > - HID_REQ_SET_REPORT); > + ret =3D hid_hw_raw_request(hdev, buf[0], dmabuf, alloc_size, HID_FEATUR= E_REPORT, > + HID_REQ_SET_REPORT); > hid_hw_power(hdev, PM_HINT_NORMAL); > return ret; > } [Severity: High] Should this test drvdata->quirks & QUIRK_KBD_REPORT_SIZE instead of the constant macro QUIRK_KBD_REPORT_SIZE? Because QUIRK_KBD_REPORT_SIZE is BIT(16), the condition is always true, forcing every feature report sent through asus_kbd_set_report() on all Asus devices (such as the 6-byte asus_kbd_get_functions() and 16-byte asus_kbd_init() reports) to 64 bytes. > @@ -718,6 +732,38 @@ static void asus_kbd_set_brightness(struct hid_devic= e *hdev, u8 brightness) > hid_err(hdev, "Asus failed to set keyboard backlight: %d\n", ret); > } > =20 > +static void asus_kbd_set_brightness_cdev(struct led_classdev *led_cdev, > + enum led_brightness brightness) > +{ > + struct asus_drvdata *drvdata =3D container_of(led_cdev, struct asus_drv= data, kbd_led_cdev); > + u8 level =3D (u8)brightness; > + > + if (level > EC_KBD_MAX_BACKLIGHT) > + level =3D EC_KBD_MAX_BACKLIGHT; > + > + asus_kbd_set_brightness(drvdata->hdev, level); > + drvdata->kbd_backlight_brightness =3D level; > +} [Severity: High] Can asus_kbd_set_brightness_cdev() sleep in atomic context? asus_kbd_set_brightness() calls asus_kbd_set_report(), which sleeps in kzalloc(..., GFP_KERNEL), hid_hw_power() and hid_hw_raw_request(). However, asus_kbd_set_brightness_cdev() is wired to the non-sleeping led_classdev.brightness_set callback (which the LED core invokes from atomic contexts such as the software blink timer and LED triggers) and is also called directly from asus_event() -> asus_kbd_illum_toggle(), which runs in USB interrupt URB completion context on USB HID keyboards when asus-wmi is absent. Using brightness_set_blocking for kbd_led_cdev (or deferring the update through drvdata->worker like asus_kbd_backlight_set()) would avoid sleeping in atomic context. > + > +static enum led_brightness asus_kbd_get_brightness_cdev(struct led_class= dev *led_cdev) > +{ > + struct asus_drvdata *drvdata =3D container_of(led_cdev, struct asus_drv= data, kbd_led_cdev); > + > + return (enum led_brightness)drvdata->kbd_backlight_brightness; > +} > + > +static void asus_kbd_illum_toggle(struct asus_drvdata *drvdata) > +{ > + if (!drvdata->kbd_led_cdev.brightness_set) > + return; > + > + u8 current_level =3D drvdata->kbd_backlight_brightness; > + u8 max_level =3D EC_KBD_MAX_BACKLIGHT; > + u8 next_level =3D (current_level + 1) % (max_level + 1); > + > + asus_kbd_set_brightness_cdev(&drvdata->kbd_led_cdev, next_level); > +} [Severity: Medium] Can concurrent calls to asus_kbd_set_brightness_cdev() race on drvdata->kbd_backlight_brightness? CPU0 (sysfs brightness_store) CPU1 (KEY_KBDILLUMTOGGLE) asus_kbd_set_brightness_cdev(2) asus_kbd_set_brightness(2) asus_kbd_illum_toggle() current_level =3D 0 asus_kbd_set_brightness_cdev(1) asus_kbd_set_brightness(1) drvdata->kbd_backlight_brightness =3D= 1 drvdata->kbd_backlight_brightness =3D 2 <-- out of sync with hardware sysfs writes hold led_cdev->led_access, asus_event() holds hdev->driver_input_lock, and asus_resume() holds neither. Because drvdata->kbd_backlight_brightness is updated only after the blocking HID transfer in asus_kbd_set_brightness(), overlapping updates read stale levels and can finish out of order. [ ... ] > @@ -1012,10 +1058,28 @@ static int asus_kbd_register_leds(struct hid_devi= ce *hdev) > drvdata->listener.brightness_set =3D asus_kbd_backlight_set; > ret =3D asus_hid_register_listener(&drvdata->listener); > if (ret < 0) { > - hid_err(hdev, "Unable to register kbd brightness listener: %d\n", ret); > + if (ret !=3D -ENODEV) { > + hid_err(hdev, "Unable to register kbd brightness listener: %d\n", ret= ); > + } > drvdata->listener.brightness_set =3D NULL; > } > =20 > + // Non-x86 architectures do not have WMI, just register a led > + // device directly > + if (ret =3D=3D -ENODEV) { > + drvdata->kbd_led_cdev.name =3D "asus::kbd_backlight"; > + drvdata->kbd_led_cdev.brightness_set =3D asus_kbd_set_brightness_cdev; > + drvdata->kbd_led_cdev.brightness_get =3D asus_kbd_get_brightness_cdev; > + drvdata->kbd_led_cdev.max_brightness =3D EC_KBD_MAX_BACKLIGHT; > + ret =3D led_classdev_register(&hdev->dev, &drvdata->kbd_led_cdev); > + if (ret < 0) { > + hid_err(hdev, "Unable to register kbd brightness led: %d\n", ret); > + drvdata->kbd_led_cdev.brightness_set =3D NULL; > + } > + > + asus_kbd_set_brightness_cdev(&drvdata->kbd_led_cdev, 1); > + } > + > return ret; > } [Severity: Medium] Does this still call asus_kbd_set_brightness_cdev() when led_classdev_register() fails? The error branch logs the failure and clears brightness_set, but falls through without returning. Also, when registration succeeds, led_classdev_register() calls led_update_brightness() -> asus_kbd_get_brightness_cdev() while drvdata->kbd_backlight_brightness is still 0, so calling asus_kbd_set_brightness_cdev(&drvdata->kbd_led_cdev, 1) afterwards sets the hardware and drvdata->kbd_backlight_brightness to 1 while leaving drvdata->kbd_led_cdev.brightness at 0. [ ... ] > @@ -1676,6 +1746,9 @@ static int asus_probe(struct hid_device *hdev, cons= t struct hid_device_id *id) > if (drvdata->xgm_led) > devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev); > =20 > + if (drvdata->kbd_led_cdev.brightness_set) > + led_classdev_unregister(&drvdata->kbd_led_cdev); > + > asus_worker_stop(drvdata->worker); > hid_hw_stop(hdev); > return ret; > @@ -1691,6 +1764,9 @@ static void asus_remove(struct hid_device *hdev) > if (drvdata->xgm_led) > devm_led_classdev_unregister(&hdev->dev, &drvdata->xgm_led->cdev); > =20 > + if (drvdata->kbd_led_cdev.brightness_set) > + led_classdev_unregister(&drvdata->kbd_led_cdev); > + > asus_worker_stop(drvdata->worker); > hid_hw_stop(hdev); > } [Severity: Medium] Can an incoming KEY_KBDILLUMTOGGLE event use drvdata->kbd_led_cdev after led_classdev_unregister()? CPU0 CPU1 asus_remove() led_classdev_unregister(&drvdata->kbd_led_cdev) asus_event() asus_kbd_illum_toggle() if (!drvdata->kbd_led_cdev.brightness= _set) asus_kbd_set_brightness_cdev() <-- uses unregistered LED and turns= backlight back on hid_hw_stop(hdev) led_classdev_unregister() turns the LED off and unregisters the device, but does not clear drvdata->kbd_led_cdev.brightness_set, while HID input events remain active until hid_hw_stop(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201185118.3426= 72-1-jaytersen@gmail.com?part=3D1