From: sashiko-bot@kernel.org
To: "Derek J. Clark" <derekjohn.clark@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3 1/4] HID: hid-msi: Add MSI Claw configuration driver
Date: Fri, 15 May 2026 04:09:27 +0000 [thread overview]
Message-ID: <20260515040928.1DBF7C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260515033622.2095277-2-derekjohn.clark@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Incorrect teardown order in `claw_remove()` creates a race condition that leaks sysfs attributes and leads to a Use-After-Free.
- [High] Unreasonably short 8ms timeout causes spurious `-EBUSY` failures on `HZ=100` systems.
- [Medium] Read-modify-write race condition in sysfs configuration handlers causes silent state corruption.
- [Medium] Missing `.suspend` callback allows hardware-interacting delayed works to execute during system sleep.
--
commit ce9aa923d32bac6eb56e73d413c94aa753ea00cf
Author: Derek J. Clark <derekjohn.clark@gmail.com>
Subject: HID: hid-msi: Add MSI Claw configuration driver
Adds configuration HID driver for the MSI Claw series of handheld PC's.
In this initial patch add the initial driver outline and attributes for
changing the gamepad mode, M-key behavior, and add a WO reset function.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> new file mode 100644
> index 0000000000000..89bb32f00bfc3
> --- /dev/null
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> +static ssize_t gamepad_mode_store(struct device *dev, struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct hid_device *hdev = to_hid_device(dev);
> + struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
> + u8 data[2] = { 0x00, drvdata->mkeys_function };
Could this lead to a read-modify-write race condition if two threads write to
the sysfs attributes simultaneously?
They read drvdata->mkeys_function locklessly to construct the command payload.
After the payload is prepared, claw_hw_output_report() is called, which then
acquires cfg_mutex to send the command. If two threads write concurrently,
the second one could overwrite the first one's change because it read a stale
state.
Should the payload construction be performed inside the cfg_mutex critical
section?
[ ... ]
> +static ssize_t gamepad_mode_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct hid_device *hdev = to_hid_device(dev);
> + struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
> + int ret, i;
> +
> + ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE, NULL, 0, 8);
Will this 8 millisecond timeout cause spurious failures on systems configured
with a 100 hz timer tick?
On such systems, msecs_to_jiffies(8) evaluates to exactly 1 jiffy. A 1-jiffy
timeout using wait_for_completion_interruptible_timeout() can expire in under
1 millisecond if the timer tick fires immediately after the wait is scheduled,
which might not provide enough time for the interrupt to complete and will
return -EBUSY.
[ ... ]
> +static void claw_remove(struct hid_device *hdev)
> +{
> + struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
> +
> + if (!drvdata) {
> + hid_hw_stop(hdev);
> + return;
> + }
> +
> + device_remove_group(&hdev->dev, &claw_gamepad_attr_group);
> + cancel_delayed_work_sync(&drvdata->cfg_setup);
Does this teardown sequence leak sysfs attributes and cause a use-after-free?
If cfg_setup_fn() is executing concurrently, device_remove_group() will do
nothing because the sysfs group has not been added yet. Then
cancel_delayed_work_sync() will wait for the work to finish.
Meanwhile, cfg_setup_fn() proceeds to call device_add_group(), adding the
sysfs attributes. When the work finishes, claw_remove() completes and drvdata
is freed. The sysfs attributes remain registered to the device, and any
subsequent read or write from userspace will trigger a use-after-free when
accessing the freed drvdata pointer.
Should cancel_delayed_work_sync() happen before device_remove_group() to
ensure correct teardown order?
[ ... ]
> +static struct hid_driver msi_driver = {
> + .name = "hid-msi",
> + .id_table = msi_devices,
> + .raw_event = msi_raw_event,
> + .probe = msi_probe,
> + .remove = msi_remove,
> + .resume = msi_resume,
> +};
Does this driver need a suspend callback?
The cfg_setup and cfg_resume delayed works are scheduled on the standard
non-freezable system workqueue. Without a suspend callback to cancel them,
these works can execute while the system is asleep.
When they fire, they will call hid_hw_output_report() on a suspended
usb device, which could cause input/output timeouts, lockups, or inadvertently
wake up the hardware.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260515033622.2095277-1-derekjohn.clark@gmail.com?part=1
next prev parent reply other threads:[~2026-05-15 4:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 3:36 [PATCH v3 0/4] Add MSI Claw HID Configuration Driver Derek J. Clark
2026-05-15 3:36 ` [PATCH v3 1/4] HID: hid-msi: Add MSI Claw configuration driver Derek J. Clark
2026-05-15 4:09 ` sashiko-bot [this message]
2026-05-15 3:36 ` [PATCH v3 2/4] HID: hid-msi: Add M-key mapping attributes Derek J. Clark
2026-05-15 4:32 ` sashiko-bot
2026-05-15 3:36 ` [PATCH v3 3/4] HID: hid-msi: Add RGB control interface Derek J. Clark
2026-05-15 5:01 ` sashiko-bot
2026-05-15 3:36 ` [PATCH v3 4/4] HID: hid-msi: Add Rumble Intensity Attributes Derek J. Clark
2026-05-15 5:26 ` sashiko-bot
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=20260515040928.1DBF7C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=derekjohn.clark@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox