From: sashiko-bot@kernel.org
To: "Aditya Dash" <mradityadash@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2 2/6] HID: hid-lenovo-go: use the right controller selectors
Date: Sun, 30 Aug 2026 15:06:57 +0000 [thread overview]
Message-ID: <20260830150658.00DFF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <876cc33bede49d8ed2437278f0696010df98643c.1788096667.git.mradityadash@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing hid_hw_stop() and hid_hw_close() in probe error paths.
- [High] Missing hardware cleanup in remove() due to early return.
- [High] Global singleton used for per-device state, causing corruption and Use-After-Free with multiple devices.
- [High] Leaked sysfs attribute groups on probe failure.
- [High] Deadlock during device unbind due to lock ordering with sysfs_remove_groups.
--
commit c2d6b2210c5ca6d1fa356349f3cbde71b00ce595
Author: Aditya Dash <mradityadash@gmail.com>
Subject: HID: hid-lenovo-go: use the right controller selectors
This commit fixes the attribute selectors for the right controller on Lenovo
Go gamepads. It updates the imu_enabled_right attribute to select
FEATURE_IMU_ENABLE and ensures the reset_right attribute targets the right
controller.
> diff --git a/drivers/hid/hid-lenovo-go.c b/drivers/hid/hid-lenovo-go.c
> index b8248bf8965c6..b937d11dd6f6a 100644
> --- a/drivers/hid/hid-lenovo-go.c
> +++ b/drivers/hid/hid-lenovo-go.c
> @@ -1999,13 +1999,13 @@ LEGO_DEVICE_ATTR_RW(imu_bypass_right, "imu_bypass_enabled", RIGHT_CONTROLLER,
[ ... ]
> static int hid_go_cfg_probe(struct hid_device *hdev,
> const struct hid_device_id *_id)
> {
> unsigned char *buf;
> int ret;
>
> buf = devm_kzalloc(&hdev->dev, GO_PACKET_SIZE, GFP_KERNEL);
> if (!buf)
> return -ENOMEM;
>
> hid_set_drvdata(hdev, &drvdata);
> drvdata.hdev = hdev;
> mutex_init(&drvdata.cfg_mutex);
[Severity: High]
This is a pre-existing issue, but does using a global singleton for instance-
specific state break the driver model if multiple devices are plugged in?
Since drvdata is globally allocated in drivers/hid/hid-lenovo-go.c, setting
drvdata.hdev here in hid_go_cfg_probe() will clobber the pointer from any
previously probed device.
>
> ret = sysfs_create_groups(&hdev->dev.kobj, top_level_attr_groups);
> if (ret) {
> dev_err_probe(&hdev->dev, ret,
> "Failed to create gamepad configuration attributes\n");
> return ret;
> }
>
> ret = devm_led_classdev_multicolor_register(&hdev->dev, &go_cdev_rgb);
[Severity: High]
This isn't a bug introduced by this patch, but does this corrupt the LED
subsystem lists?
Since go_cdev_rgb is a statically allocated global struct, registering the
same object in hid_go_cfg_probe() for every device instance could corrupt
the lists if multiple devices are present.
> if (ret) {
> dev_err_probe(&hdev->dev, ret, "Failed to create RGB device\n");
> return ret;
[Severity: High]
This is a pre-existing issue, but does this error path in hid_go_cfg_probe()
leave sysfs attributes behind?
If devm_led_classdev_multicolor_register() fails, this returns immediately
without calling sysfs_remove_groups(). While devres will free the driver's
memory, the sysfs attributes remain active and reference freed memory,
which could cause a use-after-free if userspace interacts with them.
> }
[ ... ]
> static void hid_go_cfg_remove(struct hid_device *hdev)
> {
> /*
> * cfg_setup is scheduled from hid_go_cfg_probe() with a 2 ms delay
> * and dereferences drvdata.hdev. Drain it here before tearing
> * down so the workqueue cannot run after hid_destroy_device()'s
> * put_device() has released the underlying hdev and dereference
> * a stale drvdata.hdev pointer.
> */
> cancel_delayed_work_sync(&drvdata.go_cfg_setup);
>
> guard(mutex)(&drvdata.cfg_mutex);
> sysfs_remove_groups(&hdev->dev.kobj, top_level_attr_groups);
[Severity: High]
This isn't a bug introduced by this patch, but can this lock ordering in
hid_go_cfg_remove() cause a deadlock during device unbind?
This holds drvdata.cfg_mutex while synchronously waiting for
sysfs_remove_groups() to finish. If userspace is concurrently writing to a
sysfs attribute, that write path (e.g., mcu_property_out()) will attempt
to acquire drvdata.cfg_mutex, leading to an ABBA deadlock that freezes the
kernel thread.
> hid_hw_close(hdev);
> hid_hw_stop(hdev);
> }
[ ... ]
> ep = get_endpoint_address(hdev);
> if (ep != GO_GP_INTF_IN) {
> dev_dbg(&hdev->dev, "Started interface %x as generic HID device\n", ep);
> return 0;
> }
>
> ret = hid_go_cfg_probe(hdev, id);
> if (ret)
> dev_err_probe(&hdev->dev, ret, "Failed to start configuration interface\n");
>
> dev_dbg(&hdev->dev, "Started Legion Go HID Device: %x\n", ep);
>
> return ret;
[Severity: High]
This is a pre-existing issue, but does this error path in hid_go_probe()
fail to tear down the hardware?
If hid_go_cfg_probe() fails, the error code is immediately returned without
calling hid_hw_stop() or hid_hw_close(). The hardware is left running while
driver private data is freed by devres, which will trigger a use-after-free
when subsequent input events arrive.
> }
>
> static void hid_go_remove(struct hid_device *hdev)
> {
> int ep = get_endpoint_address(hdev);
>
> if (ep <= 0)
> return;
[Severity: High]
This isn't a bug introduced by this patch, but does this early return in
hid_go_remove() skip mandatory hardware cleanup?
If get_endpoint_address() fails during device unplug, it hits this early
return and bypasses hid_hw_close() and hid_hw_stop(). Input interrupts
will keep firing into freed driver structures.
>
> switch (ep) {
> case GO_GP_INTF_IN:
> hid_go_cfg_remove(hdev);
> break;
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788096666.git.mradityadash@gmail.com?part=2
next prev parent reply other threads:[~2026-08-30 15:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-30 14:56 [PATCH v2 0/6] HID: hid-lenovo-go: fix controller configuration Aditya Dash
2026-08-30 14:56 ` [PATCH v2 1/6] HID: hid-lenovo-go: use the correct calibration commands Aditya Dash
2026-08-30 15:09 ` sashiko-bot
2026-08-30 14:56 ` [PATCH v2 2/6] HID: hid-lenovo-go: use the right controller selectors Aditya Dash
2026-08-30 15:06 ` sashiko-bot [this message]
2026-08-30 14:56 ` [PATCH v2 3/6] HID: hid-lenovo-go: return configuration request errors Aditya Dash
2026-08-30 15:09 ` sashiko-bot
2026-08-30 14:56 ` [PATCH v2 4/6] HID: hid-lenovo-go: normalize calibration failure status Aditya Dash
2026-08-30 15:08 ` sashiko-bot
2026-08-30 14:56 ` [PATCH v2 5/6] HID: hid-lenovo-go: reject unknown calibration action Aditya Dash
2026-08-30 15:08 ` sashiko-bot
2026-08-30 14:56 ` [PATCH v2 6/6] HID: hid-lenovo-go: clear calibration status on start Aditya Dash
2026-08-30 15:09 ` sashiko-bot
2026-08-31 23:35 ` [PATCH v2 0/6] HID: hid-lenovo-go: fix controller configuration Derek John Clark
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=20260830150658.00DFF1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=mradityadash@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.