From: sashiko-bot@kernel.org
To: "Derek J. Clark" <derekjohn.clark@gmail.com>
Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH 4/8] HID: hid-msi: Re-init on reset during resume
Date: Fri, 04 Dec 2026 00:37:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-248837@kernel.org> (raw)
In-Reply-To: <20261204001846.3801336-5-derekjohn.clark@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] HID: hid-msi: claw_profile_event() races with LED core and
RGB apply helpers
- [Medium] HID: hid-msi: unsynchronized RGB resync in cfg_setup_fn()
races RGB writes
- [Medium] HID: hid-msi: claw_switch_mode() ignores pending resync after
reset_resume
- [Medium] HID: hid-msi: reset_resume RGB resync leaves rgb_enabled
stale
- [Low] HID: hid-msi: commit message misstates gamepad_mode_show() and
profile writes
--
commit 23e1138cfde0075a6df1d941aff2218169863ed7
Author: Derek J. Clark <derekjohn.clark@gmail.com>
HID: hid-msi: Re-init on reset during resume
This commit adds a .reset_resume callback to hid-msi that sets a resync
flag so cfg_setup_fn() re-reads the gamepad mode and RGB profile after a
device reset during resume.
> A resume that resets the device goes to .reset_resume, which hid-msi
> does not currently implement. The driver keeps its pre-suspend view of
> the MCU, so gamepad_mode reports a mode the MCU is not in and the next
> write pushes the stale mkeys_function back to it.
[ ... ]
> The RGB re-read also makes claw_profile_event() a runtime writer of
> rgb_speed and led_cdev.brightness. Before it, that handler reached those
> fields only during probe.
[Severity: Low]
Two details in the commit message do not quite match the code.
First, gamepad_mode_show() sends CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE to
query the MCU on every sysfs read, so it does not report a stale cached
mode; it is the cached fields used by claw_switch_mode() on writes (and
cached RGB attributes) that remain stale until re-read.
Second, claw_profile_event() also becomes a runtime writer of
drvdata->rgb_frames[] and drvdata->led_mc.subled_info[0..2].intensity,
not only rgb_speed and led_cdev.brightness.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index c7b7399ef930e..606ff7d652766 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> @@ -1753,6 +1754,10 @@ static void cfg_setup_fn(struct work_struct *work)
>
> /* Add sysfs attributes after we get the device state */
> try_gamepad:
> + if (gamepad_ready && (rgb_ready || !drvdata->rgb_addr))
> + /* Pairs with smp_load_acquire from cfg_resume_fn in system_percpu_wq context */
> + smp_store_release(&drvdata->resync, false);
[Severity: Medium]
Does the RGB resync leave drvdata->rgb_enabled stale after a reset?
If RGB was disabled via enabled=0 without committing to flash via apply,
a reset during suspend reloads the lit ROM profile. cfg_setup_fn() then
re-reads the frames and updates brightness and subled_info intensities,
but never reconciles drvdata->rgb_enabled.
enabled_show() then reports false while the LEDs are lit, and the next
write to brightness, multi_intensity, speed, or effect runs
claw_apply_rgb_state() -> claw_apply_disabled(), turning the LEDs off.
Reconciling drvdata->rgb_enabled from the read-back frames (or resetting
it on resync to match claw_probe()) would keep it in sync.
[ ... ]
> @@ -1811,12 +1816,19 @@ static void cfg_resume_fn(struct work_struct *work)
> {
> struct delayed_work *dwork = container_of(work, struct delayed_work, work);
> struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, cfg_resume);
> + bool gp_registered, rgb_registered, resync;
> +
> + /* Pairs with smp_load_acquire from claw_resume in process context */
> + resync = smp_load_acquire(&drvdata->resync);
> +
> + scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
> + /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
> + gp_registered = smp_load_acquire(&drvdata->gp_registered);
> + /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
> + rgb_registered = smp_load_acquire(&drvdata->rgb_registered);
> + }
>
> - guard(spinlock_irqsave)(&drvdata->registration_lock);
> - /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
> - if (!smp_load_acquire(&drvdata->gp_registered) ||
> - /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
> - !smp_load_acquire(&drvdata->rgb_registered))
> + if (resync || !gp_registered || !rgb_registered)
> schedule_delayed_work(&drvdata->cfg_setup, msecs_to_jiffies(500));
> }
[Severity: Medium]
Can running claw_read_rgb_config() while the LED device is registered
race on led_cdev.brightness and subled_info[0..2].intensity?
Once rgb_registered is true, claw_profile_event() runs in atomic USB URB
completion context holding frame_lock and writes LED-core-owned fields
directly, while the LED core synchronizes them with led_cdev->led_access
(a mutex) and never takes frame_lock:
CPU0 (URB completion) CPU1 (sysfs write)
claw_profile_event() multi_intensity_store()
spin_lock(&frame_lock) mutex_lock(&led_cdev->led_access)
led_cdev.brightness = ... subled_info[0..2].intensity = ...
subled_info[0..2].intensity = ... <-- data race / torn RGB tuple
Inside hid-msi, claw_apply_monocolor() and claw_apply_breathe() also read
subled_info[0..2].intensity without frame_lock or led_access, and
led_set_brightness_nosleep() writes led_cdev.brightness without
frame_lock, risking torn RGB tuples or clobbered brightness.
[Severity: Medium]
Is claw_read_rgb_config() serialized against concurrent RGB writes
during a reset-resume resync?
claw_read_rgb_config() holds profile_mutex across its 8-frame loop while
claw_write_rgb_state() holds rom_mutex, and cfg_mutex is dropped between
individual frames. If userspace writes an RGB attribute and triggers
apply_store() during the resync, reads and writes interleave per frame:
CPU0 (system_percpu_wq) CPU1 (apply_store / system_dfl_wq)
claw_read_rgb_config() apply_store()
/* frame f read */ flush_delayed_work(&rgb_queue)
claw_profile_event() claw_write_rgb_state()
rgb_frames[f] = old_mcu_data /* reads overwritten frame f */
send rgb_frames[f] <-- mixed data
SYNC_TO_ROM <-- saved
A concurrent write to speed, brightness, or multi_intensity before frame
0's READ_PROFILE_ACK arrives can also be silently clobbered by stale MCU
values in claw_profile_event(). Serializing claw_read_rgb_config() with
RGB writes (for example under rom_mutex) would prevent both races.
[ ... ]
> @@ -2003,19 +2015,24 @@ static void msi_remove(struct hid_device *hdev)
> hid_hw_stop(hdev);
> }
>
> -static int claw_resume(struct hid_device *hdev)
> +static int claw_resume(struct hid_device *hdev, bool resync)
> {
> struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
>
> if (!drvdata)
> return -ENODEV;
>
> + if (resync) {
> + /* Pairs with smp_load_acquire from cfg_resume_fn in system_percpu_wq context */
> + smp_store_release(&drvdata->resync, true);
> + }
> +
> /* MCU can take up to 500ms to be ready after resume */
> schedule_delayed_work(&drvdata->cfg_resume, msecs_to_jiffies(500));
> return 0;
> }
[Severity: Medium]
What prevents claw_switch_mode() from pushing stale cached state while
drvdata->resync is still pending?
After a reset-resume, claw_resume() and cfg_resume_fn() introduce a
1000 ms delay before cfg_setup_fn() re-reads gamepad_mode and
mkeys_function. A sysfs write to either attribute in that window calls
claw_switch_mode() and sends the stale pre-suspend companion field.
In addition, if CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE fails transiently in
cfg_setup_fn(), drvdata->resync stays true without rescheduling
cfg_setup, leaving that stale-write window open until a sysfs read or
another suspend/resume cycle.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204001846.3801336-1-derekjohn.clark@gmail.com?part=4
next prev parent reply other threads:[~2026-12-04 0:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
2026-12-04 0:18 ` [PATCH 1/8] HID: hid-msi: Queue the RGB work item on system_dfl_wq Derek J. Clark
2026-12-04 0:18 ` [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute Derek J. Clark
2026-12-04 0:35 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 3/8] HID: hid-msi: Protect the RGB state with frame_lock Derek J. Clark
2026-12-04 0:18 ` [PATCH 4/8] HID: hid-msi: Re-init on reset during resume Derek J. Clark
2026-12-04 0:37 ` sashiko-bot [this message]
2026-12-04 0:18 ` [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend Derek J. Clark
2026-12-04 0:38 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Derek J. Clark
2026-12-04 0:32 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 7/8] HID: hid-msi: Switch the RGB LED to brightness_set_blocking Derek J. Clark
2026-12-04 0:39 ` sashiko-bot
2026-12-04 0:18 ` [PATCH 8/8] USB: core: quirks: Add RESET_RESUME quirk for MSI Claw Derek J. Clark
2026-12-04 0:39 ` [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes 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=sashiko-outbox-248837@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=derekjohn.clark@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-usb@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