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 7/8] HID: hid-msi: Switch the RGB LED to brightness_set_blocking
Date: Fri, 04 Dec 2026 00:39:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-248840@kernel.org> (raw)
In-Reply-To: <20261204001846.3801336-8-derekjohn.clark@gmail.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] HID: hid-msi: non-blocking callback registered as
brightness_set_blocking
- [Medium] HID: hid-msi: apply_store() races with set_brightness_work
before SYNC_TO_ROM
- [Medium] HID: hid-msi: claw_write_rgb_state() clobbers concurrent
rgb_dirty updates
- [Medium] HID: hid-msi: brightness_set_blocking exposes lost brightness
update race
- [Medium] HID: hid-msi: claw_led_brightness_set_blocking() races on
led_cdev->brightness
- [Medium] HID: hid-msi: unflushed brightness work breaks suspend drain
and rgb_dirty
- [Low] HID: hid-msi: commit message omits new led_cdev->brightness
assignment
--
commit 16672f0371737d043ea0a0ea456c2660ded1fb00
Author: Derek J. Clark <derekjohn.clark@gmail.com>
> HID: hid-msi: Switch the RGB LED to brightness_set_blocking
>
> brightness_set must not sleep, so led-core may call it from the blink
> timer or a trigger's hardirq. The work this handler queues is an HID
> transaction, so register brightness_set_blocking instead, like
> hid-playstation does for the DualSense lightbar.
>
> No path that led-core uses to reach this handler sleeps, so this is an
> interface correction rather than a bug fix.
>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
[Severity: Low]
Should the commit message also describe the new frame_lock-protected
assignment and clamping of led_cdev->brightness in
claw_led_brightness_set_blocking()? The previous claw_led_brightness_set()
ignored its brightness parameter, so mutating led_cdev->brightness is a
behavioral change beyond switching the callback interface.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index d2cd0d7397aa4..f4b592c7d2977 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c
> @@ -1716,8 +1716,8 @@ static ssize_t speed_range_show(struct device *dev,
> }
> static DEVICE_ATTR_RO(speed_range);
>
> -static void claw_led_brightness_set(struct led_classdev *led_cdev,
> - enum led_brightness _brightness)
> +static int claw_led_brightness_set_blocking(struct led_classdev *led_cdev,
> + enum led_brightness brightness)
> {
> struct led_classdev_mc *led_mc = container_of(led_cdev, struct led_classdev_mc, led_cdev);
> struct claw_drvdata *drvdata = container_of(led_mc, struct claw_drvdata, led_mc);
> @@ -1725,10 +1725,16 @@ static void claw_led_brightness_set(struct led_classdev *led_cdev,
> scoped_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->rgb_registered))
> - return;
> + return 0;
> }
>
> + scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
> + led_cdev->brightness = min_t(unsigned int, brightness,
> + led_cdev->max_brightness);
[Severity: Medium]
Does writing led_cdev->brightness here introduce a data race with led-core?
claw_led_brightness_set_blocking() runs asynchronously on leds_wq without
led_cdev->led_access and only holds drvdata->frame_lock, whereas led-core
reads and writes led_cdev->brightness without frame_lock in
led_set_brightness_nosleep(), multi_intensity_store(), brightness_show(),
and led_timer_function().
CPU0 (leds_wq) CPU1 (sysfs)
set_brightness_delayed()
clear LED_SET_BRIGHTNESS
claw_led_brightness_set_blocking(10)
brightness_store(80)
led_cdev->brightness = 80
delayed_set_value = 80
set LED_SET_BRIGHTNESS
led_cdev->brightness = 10 <-- overwrites newer value
multi_intensity_store()
led_set_brightness(10)
delayed_set_value = 10
When multi_intensity_store() reads the clobbered value while
LED_SET_BRIGHTNESS is set, it overwrites delayed_set_value and permanently
drops the newer brightness; the same race with led_timer_function() can
corrupt software blink phase and blink_brightness. Storing a separate
frame_lock-protected brightness field in struct claw_drvdata for
claw_write_rgb_state() would avoid mutating led_cdev->brightness.
> claw_rgb_schedule(drvdata);
> +
> + return 0;
> }
[Severity: Medium]
Can claw_write_rgb_state() clobber drvdata->rgb_dirty when
claw_rgb_schedule() runs concurrently?
claw_write_rgb_state() snapshots the RGB state, runs sleeping
claw_hw_output_report() transfers, and then unconditionally clears
drvdata->rgb_dirty without serializing against claw_rgb_schedule():
CPU0 (rgb_queue) CPU1 (sysfs / suspend)
claw_write_rgb_state()
snapshot RGB state
claw_hw_output_report() ...
claw_rgb_schedule()
rgb_dirty = true
mod_delayed_work(rgb_queue, 50ms)
rgb_dirty = false <-- clobbers pending dirty flag
claw_suspend()
cancel_delayed_work_sync(rgb_queue)
If the system suspends before the 50 ms delayed work fires, claw_suspend()
cancels rgb_queue while rgb_dirty is false, so cfg_resume_fn() skips
replaying the newer RGB update on resume.
[ ... ]
> @@ -1946,7 +1952,7 @@ static int claw_probe(struct hid_device *hdev, u8 ep)
> drvdata->led_mc.led_cdev.brightness = 0x50;
> drvdata->led_mc.led_cdev.max_brightness = 0x64;
> drvdata->led_mc.led_cdev.color = LED_COLOR_ID_RGB;
> - drvdata->led_mc.led_cdev.brightness_set = claw_led_brightness_set;
> + drvdata->led_mc.led_cdev.brightness_set_blocking = claw_led_brightness_set_blocking;
[Severity: Medium]
Should this stay on brightness_set instead of switching to
brightness_set_blocking?
claw_led_brightness_set_blocking() does not sleep or perform HID I/O; it
only takes irqsave spinlocks and calls mod_delayed_work(), which is safe
in atomic context. Per include/linux/leds.h, brightness_set_blocking is
for callbacks that synchronously update hardware, so registering a work
scheduler there makes led_set_brightness_sync() return 0 before the 50 ms
delayed HID write runs and forces every led_set_brightness_nopm() call
through the single-threaded global ordered leds_wq just to queue
drvdata->rgb_queue.
[Severity: Medium]
Can apply_store() now commit stale RGB state to ROM before a pending
brightness or multi_intensity write is scheduled?
With brightness_set cleared, brightness_store() and multi_intensity_store()
queue led_cdev->set_brightness_work on leds_wq and return before
claw_rgb_schedule() runs, while apply_store() only flushes
drvdata->rgb_queue:
CPU0 (userspace) CPU1 (leds_wq)
brightness_store()
queue_work(set_brightness_work)
apply_store()
flush_delayed_work(rgb_queue) <-- nothing queued yet
SYNC_TO_ROM <-- commits stale MCU state
set_brightness_delayed()
claw_rgb_schedule()
If set_brightness_work has not run yet when userspace writes to apply,
CLAW_COMMAND_TYPE_SYNC_TO_ROM persists the old RGB state to flash and the
new setting is lost across a reset.
[Severity: Medium]
Does switching to brightness_set_blocking expose multi_intensity_store() to
dropping a pending brightness update?
When a second non-zero brightness_store() arrives while LED_SET_BRIGHTNESS
is still pending, led_set_brightness() updates led_cdev->delayed_set_value
and returns early without updating led_cdev->brightness. If
multi_intensity_store() then runs before set_brightness_work executes, it
passes the stale led_cdev->brightness back into led_set_brightness(),
overwriting delayed_set_value and silently discarding the newer brightness.
[Severity: Medium]
Does deferring claw_rgb_schedule() onto leds_wq break the suspend drain in
claw_suspend() and the rgb_dirty protection across reset-resume?
leds_wq is a global ordered workqueue without WQ_FREEZABLE, and
claw_suspend() cancels cfg_resume, cfg_setup, and rgb_queue without
draining led_cdev->set_brightness_work:
CPU0 (sysfs / PM) CPU1 (leds_wq)
multi_intensity_store()
update subled_info[].intensity
queue_work(set_brightness_work)
claw_suspend()
cancel_delayed_work_sync(rgb_queue)
msi_reset_resume()
cfg_setup_fn()
rgb_dirty == false
claw_read_rgb_config() <-- overwrites subled_info with stale color
set_brightness_delayed()
claw_rgb_schedule() <-- uses stale color
Because multi_intensity_store() updates subled_info[].intensity in place
and returns before rgb_dirty is set, set_brightness_work can re-arm
rgb_queue during suspend or remain pending until cfg_setup_fn() runs on
reset-resume (the default path with commit "USB: core: quirks: Add
RESET_RESUME quirk for MSI Claw"), where claw_profile_event() overwrites
subled_info with the stale MCU color and permanently loses the user's color
update.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204001846.3801336-1-derekjohn.clark@gmail.com?part=7
next prev parent reply other threads:[~2026-12-04 0:39 UTC|newest]
Thread overview: 14+ 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
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 [this message]
2026-12-04 0:18 ` [PATCH 8/8] USB: core: quirks: Add RESET_RESUME quirk for MSI Claw Derek J. 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=sashiko-outbox-248840@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