* [PATCH 1/8] HID: hid-msi: Queue the RGB work item on system_dfl_wq
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
@ 2026-12-04 0:18 ` 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
` (6 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark
system_wq is deprecated. Queuing work on it warns:
workqueue: work func claw_rgb_queue_fn [hid_msi] enqueued on deprecated
workqueue. Use system_{percpu|dfl}_wq instead.
The RGB work item writes up to eight HID reports to the MCU and blocks
waiting for each reply, so move it to system_dfl_wq. That is the unbound
system workqueue, and other HID drivers queue comparable MCU transactions
there.
The ordering comments name system_wq as the workqueue the paired stores
run on. The configuration work is queued with schedule_delayed_work(),
which now uses system_percpu_wq, so rename the workqueue to the one those
pairs now run on.
Fixes: f27e2e3c80ed ("HID: hid-msi: Add RGB control interface")
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 54 +++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index 23d731f700c9..d4128955e463 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -685,7 +685,7 @@ static ssize_t gamepad_mode_store(struct device *dev, struct device_attribute *a
int i, ret = -EINVAL;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -714,7 +714,7 @@ static ssize_t gamepad_mode_show(struct device *dev,
int ret, i;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -760,7 +760,7 @@ static ssize_t mkeys_function_store(struct device *dev, struct device_attribute
int i, ret = -EINVAL;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -789,7 +789,7 @@ static ssize_t mkeys_function_show(struct device *dev, struct device_attribute *
int ret, i;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -832,7 +832,7 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
int ret;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -889,7 +889,7 @@ static int claw_mkey_store(struct device *dev, const char *buf, u8 mkey)
int ret, key_count, i;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -939,7 +939,7 @@ static int claw_mkey_show(struct device *dev, char *buf, enum claw_key_index m_k
u8 *codes;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -1034,7 +1034,7 @@ static ssize_t rumble_intensity_left_store(struct device *dev,
int ret;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -1077,7 +1077,7 @@ static ssize_t rumble_intensity_left_show(struct device *dev,
u8 val;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -1108,7 +1108,7 @@ static ssize_t rumble_intensity_right_store(struct device *dev,
int ret;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -1151,7 +1151,7 @@ static ssize_t rumble_intensity_right_show(struct device *dev,
u8 val;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->gp_registered))
return -ENODEV;
}
@@ -1472,7 +1472,7 @@ static void claw_rgb_queue_fn(struct work_struct *work)
return;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return;
}
@@ -1492,7 +1492,7 @@ static ssize_t effect_store(struct device *dev,
int ret;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return -ENODEV;
}
@@ -1504,7 +1504,7 @@ static ssize_t effect_store(struct device *dev,
scoped_guard(spinlock_irqsave, &drvdata->profile_lock)
drvdata->rgb_effect = ret;
- mod_delayed_work(system_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
return count;
}
@@ -1517,7 +1517,7 @@ static ssize_t effect_show(struct device *dev,
struct claw_drvdata *drvdata = container_of(led_mc, struct claw_drvdata, led_mc);
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return -ENODEV;
}
@@ -1556,7 +1556,7 @@ static ssize_t enabled_store(struct device *dev,
int ret;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return -ENODEV;
}
@@ -1568,7 +1568,7 @@ static ssize_t enabled_store(struct device *dev,
scoped_guard(spinlock_irqsave, &drvdata->profile_lock)
drvdata->rgb_enabled = val;
- mod_delayed_work(system_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
return count;
}
@@ -1581,7 +1581,7 @@ static ssize_t enabled_show(struct device *dev,
struct claw_drvdata *drvdata = container_of(led_mc, struct claw_drvdata, led_mc);
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return -ENODEV;
}
@@ -1607,7 +1607,7 @@ static ssize_t speed_store(struct device *dev, struct device_attribute *attr,
int ret;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return -ENODEV;
}
@@ -1625,7 +1625,7 @@ static ssize_t speed_store(struct device *dev, struct device_attribute *attr,
scoped_guard(spinlock_irqsave, &drvdata->profile_lock)
drvdata->rgb_speed = speed;
- mod_delayed_work(system_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
return count;
}
@@ -1639,7 +1639,7 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
u8 speed = 20 - drvdata->rgb_speed;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return -ENODEV;
}
@@ -1662,12 +1662,12 @@ static void claw_led_brightness_set(struct led_classdev *led_cdev,
struct claw_drvdata *drvdata = container_of(led_mc, struct claw_drvdata, led_mc);
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
if (!smp_load_acquire(&drvdata->rgb_registered))
return;
}
- mod_delayed_work(system_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
}
static struct attribute *claw_rgb_attrs[] = {
@@ -1786,9 +1786,9 @@ static void cfg_resume_fn(struct work_struct *work)
struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, cfg_resume);
guard(spinlock_irqsave)(&drvdata->registration_lock);
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* 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_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
!smp_load_acquire(&drvdata->rgb_registered))
schedule_delayed_work(&drvdata->cfg_setup, msecs_to_jiffies(500));
}
@@ -1936,11 +1936,11 @@ static void claw_remove(struct hid_device *hdev)
cancel_delayed_work_sync(&drvdata->cfg_setup);
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* 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_load_acquire in attribute show/store functions */
smp_store_release(&drvdata->gp_registered, false);
- /* Pairs with smp_store_release from cfg_setup_fn in system_wq context */
+ /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
rgb_registered = smp_load_acquire(&drvdata->rgb_registered);
/* Pairs with smp_load_acquire in attribute show/store functions */
smp_store_release(&drvdata->rgb_registered, false);
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute
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 ` 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
` (5 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark, stable
Four write paths end with SYNC_TO_ROM, the command that copies the MCU
working copy to its internal flash. They are the M-key store behind
button_m1 and button_m2, rumble_intensity_left/right and the RGB state
write behind effect, speed and enabled.
Changes to settings without SYNC_TO_ROM survive until the MCU is power
cycled, so a write on every change adds unnecessary wear on the internal
flash. Add a write-only attribute, apply, that issues SYNC_TO_ROM on
demand and drop it from those four paths.
This changes how userspace interacts, though it isn't a critical
difference. Users who want the changes to persist will need to do an
additional step, but most users are using userspace tools that set the
last configured state on startup already. Every store currently reaches
the flash, causing excess wear, and the life of the chip outweighs
userspace ABI stability in this case.
Fixes: 93ff13ed1c4b ("HID: hid-msi: Add M-key mapping attributes")
Fixes: 95547c53f1c6 ("HID: hid-msi: Add Rumble Intensity Attributes")
Fixes: f27e2e3c80ed ("HID: hid-msi: Add RGB control interface")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 72 +++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 34 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index d4128955e463..0e1e5e6f664d 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -340,7 +340,7 @@ struct claw_drvdata {
struct hid_device *hdev;
bool orphan_ack_pending;
struct mutex cfg_mutex; /* mutex for synchronous data */
- struct mutex rom_mutex; /* mutex for SYNC_TO_ROM calls */
+ struct mutex rom_mutex; /* Serialises profile writes and the ROM commit */
spinlock_t cmd_lock; /* Lock for cmd data read/write */
u8 waiting_cmd;
int cmd_status;
@@ -852,6 +852,39 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_WO(reset);
+static ssize_t apply_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);
+ bool val;
+ int ret;
+
+ 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->gp_registered))
+ return -ENODEV;
+ }
+
+ ret = kstrtobool(buf, &val);
+ if (ret)
+ return ret;
+
+ if (!val)
+ return -EINVAL;
+
+ flush_delayed_work(&drvdata->rgb_queue);
+
+ guard(mutex)(&drvdata->rom_mutex);
+
+ ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
+ if (ret)
+ return ret;
+
+ return count;
+}
+static DEVICE_ATTR_WO(apply);
+
static int mkey_mapping_name_to_code(const char *name)
{
int i;
@@ -918,12 +951,6 @@ static int claw_mkey_store(struct device *dev, const char *buf, u8 mkey)
(u8 *)&report, sizeof(report), 25);
if (ret)
return ret;
- /* MCU will not send ACK until the USB transaction completes. ACK is sent
- * immediately after and will hit the stale state machine, before the next
- * command re-arms the state machine. Timeout 0 ensures no deadlock waiting
- * for ACK that ill never come.
- */
- ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
}
return ret;
@@ -1054,15 +1081,6 @@ static ssize_t rumble_intensity_left_store(struct device *dev,
if (ret)
return ret;
- /* MCU will not send ACK until the USB transaction completes. ACK is sent
- * immediately after and will hit the stale state machine, before the next
- * command re-arms the state machine. Timeout 0 ensures no deadlock waiting
- * for ACK that ill never come.
- */
- ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
- if (ret)
- return ret;
-
return count;
}
@@ -1128,15 +1146,6 @@ static ssize_t rumble_intensity_right_store(struct device *dev,
if (ret)
return ret;
- /* MCU will not send ACK until the USB transaction completes. ACK is sent
- * immediately after and will hit the stale state machine, before the next
- * command re-arms the state machine. Timeout 0 ensures no deadlock waiting
- * for ACK that ill never come.
- */
- ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
- if (ret)
- return ret;
-
return count;
}
@@ -1196,7 +1205,8 @@ static umode_t claw_gamepad_attr_is_visible(struct kobject *kobj, struct attribu
attr == &dev_attr_gamepad_mode_index.attr ||
attr == &dev_attr_mkeys_function.attr ||
attr == &dev_attr_mkeys_function_index.attr ||
- attr == &dev_attr_reset.attr)
+ attr == &dev_attr_reset.attr ||
+ attr == &dev_attr_apply.attr)
return attr->mode;
/* Hide rumble attrs if not supported */
@@ -1218,6 +1228,7 @@ static struct attribute *claw_gamepad_attrs[] = {
&dev_attr_mkeys_function.attr,
&dev_attr_mkeys_function_index.attr,
&dev_attr_reset.attr,
+ &dev_attr_apply.attr,
&dev_attr_rumble_intensity_left.attr,
&dev_attr_rumble_intensity_right.attr,
&dev_attr_rumble_intensity_range.attr,
@@ -1292,14 +1303,7 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata)
write_addr += CLAW_RGB_FRAME_OFFSET;
}
- /* MCU will not send ACK until the USB transaction completes. ACK is sent
- * immediately after and will hit the stale state machine, before the next
- * command re-arms the state machine. Timeout 0 ensures no deadlock waiting
- * for ACK that ill never come.
- */
- ret = claw_hw_output_report(drvdata->hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
-
- return ret;
+ return 0;
}
/* Fill all zones with the same color */
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute
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
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-04 0:35 UTC (permalink / raw)
To: Derek J. Clark; +Cc: linux-input, linux-usb, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] HID: hid-msi: apply_store() commits partial RGB state to ROM
on write error
- [Low] HID: hid-msi: misleading apply sysfs attribute name and missing
ABI doc
--
commit 0c08f61745723f69403b20ee03ff62127d32c4f4
Author: Derek J. Clark <derekjohn.clark@gmail.com>
HID: hid-msi: Move the ROM commit to an explicit apply attribute
This commit removes CLAW_COMMAND_TYPE_SYNC_TO_ROM from the M-key, rumble, and
RGB write paths and exposes it through a new write-only apply sysfs attribute
to reduce internal flash wear.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index d4128955e4637..0e1e5e6f664da 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> @@ -852,6 +852,39 @@ static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
> }
> static DEVICE_ATTR_WO(reset);
>
> +static ssize_t apply_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);
> + bool val;
> + int ret;
> +
> + 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->gp_registered))
> + return -ENODEV;
> + }
> +
> + ret = kstrtobool(buf, &val);
> + if (ret)
> + return ret;
> +
> + if (!val)
> + return -EINVAL;
> +
> + flush_delayed_work(&drvdata->rgb_queue);
> +
> + guard(mutex)(&drvdata->rom_mutex);
> +
> + ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
> + if (ret)
> + return ret;
> +
> + return count;
> +}
[Severity: Medium]
Can apply_store() commit a partial RGB frame table to flash if the
flushed RGB write fails?
claw_rgb_queue_fn() runs claw_apply_rgb_state() -> claw_write_rgb_state(),
which writes frames in a loop and returns early on a transfer error or ACK
timeout. claw_rgb_queue_fn() logs and discards that error, so
apply_store() still sends CLAW_COMMAND_TYPE_SYNC_TO_ROM and returns count.
Before this patch, an early return in claw_write_rgb_state() skipped the
ROM commit. Recording the RGB write status in drvdata and checking it
under rom_mutex in apply_store() would prevent persisting a partially
updated table and propagate the error to userspace.
> +static DEVICE_ATTR_WO(apply);
[Severity: Low]
Is "apply" a misleading name for a flash commit attribute? The M-key,
rumble, and RGB write paths already apply changes immediately to the active
MCU state, whereas this attribute commits that state to internal flash.
Naming it apply suggests changes are staged until written, which could lead
userspace tools to invoke flash writes after every change and undo the wear
reduction; a name like commit or save_settings would be clearer.
The new sysfs attribute also lacks documentation under
Documentation/ABI/testing/ explaining its behavior and flash-wear impact.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204001846.3801336-1-derekjohn.clark@gmail.com?part=2
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 3/8] HID: hid-msi: Protect the RGB state with frame_lock
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:18 ` Derek J. Clark
2026-12-04 0:18 ` [PATCH 4/8] HID: hid-msi: Re-init on reset during resume Derek J. Clark
` (4 subsequent siblings)
7 siblings, 0 replies; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark, stable
The driver keeps one spinlock per data family and takes it on both sides
of the MCU. The reply handler and the attribute paths use the same lock
for the same field, and profile_lock only publishes which reply is
outstanding. The RGB family does not follow that. claw_profile_event()
writes rgb_frames, rgb_speed and led_cdev.brightness under frame_lock,
while effect_store(), enabled_store() and speed_store() wrote their field
under profile_lock, and claw_apply_rgb_state(), effect_show() and
enabled_show() read them with no lock at all.
Take frame_lock for the whole family. claw_apply_rgb_state() reads the
effect selection before calling the apply helpers, which take that lock
themselves to write the frame data, and claw_write_rgb_state() builds
its report from one critical section, so a store landing mid-sample
cannot produce a report that mixes values the MCU was never given.
Fixes: f27e2e3c80ed ("HID: hid-msi: Add RGB control interface")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 47 ++++++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index 0e1e5e6f664d..c7b7399ef930 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -366,7 +366,7 @@ struct claw_drvdata {
enum claw_rgb_effect_index rgb_effect;
struct led_classdev_mc led_mc;
struct delayed_work rgb_queue;
- spinlock_t frame_lock; /* lock for rgb_frames read/write */
+ spinlock_t frame_lock; /* Lock for RGB state read/write */
bool rgb_registered;
u8 rgb_frame_count;
bool rgb_enabled;
@@ -1273,8 +1273,7 @@ static int claw_read_rgb_config(struct hid_device *hdev)
static int claw_write_rgb_state(struct claw_drvdata *drvdata)
{
struct claw_rgb_report report = { {0x01, 0}, CLAW_RGB_FRAME_OFFSET, 0x00,
- drvdata->rgb_frame_count, 0x09, drvdata->rgb_speed,
- drvdata->led_mc.led_cdev.brightness };
+ drvdata->rgb_frame_count, 0x09, 0, 0 };
u16 write_addr = drvdata->rgb_addr;
int f, ret;
@@ -1284,6 +1283,11 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata)
if (!drvdata->rgb_frame_count)
return -EINVAL;
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock) {
+ report.speed = drvdata->rgb_speed;
+ report.brightness = drvdata->led_mc.led_cdev.brightness;
+ }
+
guard(mutex)(&drvdata->rom_mutex);
/* Loop through (up to) 8 pages of RGB data */
for (f = 0; f < drvdata->rgb_frame_count; f++) {
@@ -1446,10 +1450,18 @@ static int claw_apply_frostfire(struct claw_drvdata *drvdata)
/* Apply current state to device */
static int claw_apply_rgb_state(struct claw_drvdata *drvdata)
{
- if (!drvdata->rgb_enabled)
+ enum claw_rgb_effect_index effect;
+ bool enabled;
+
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock) {
+ enabled = drvdata->rgb_enabled;
+ effect = drvdata->rgb_effect;
+ }
+
+ if (!enabled)
return claw_apply_disabled(drvdata);
- switch (drvdata->rgb_effect) {
+ switch (effect) {
case CLAW_RGB_EFFECT_MONOCOLOR:
return claw_apply_monocolor(drvdata);
case CLAW_RGB_EFFECT_BREATHE:
@@ -1505,7 +1517,7 @@ static ssize_t effect_store(struct device *dev,
if (ret < 0)
return ret;
- scoped_guard(spinlock_irqsave, &drvdata->profile_lock)
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
drvdata->rgb_effect = ret;
mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
@@ -1519,6 +1531,7 @@ static ssize_t effect_show(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
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);
+ enum claw_rgb_effect_index effect;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
/* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
@@ -1526,10 +1539,13 @@ static ssize_t effect_show(struct device *dev,
return -ENODEV;
}
- if (drvdata->rgb_effect >= ARRAY_SIZE(claw_rgb_effect_text))
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
+ effect = drvdata->rgb_effect;
+
+ if (effect >= ARRAY_SIZE(claw_rgb_effect_text))
return -EINVAL;
- return sysfs_emit(buf, "%s\n", claw_rgb_effect_text[drvdata->rgb_effect]);
+ return sysfs_emit(buf, "%s\n", claw_rgb_effect_text[effect]);
}
static DEVICE_ATTR_RW(effect);
@@ -1569,7 +1585,7 @@ static ssize_t enabled_store(struct device *dev,
if (ret)
return ret;
- scoped_guard(spinlock_irqsave, &drvdata->profile_lock)
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
drvdata->rgb_enabled = val;
mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
@@ -1583,6 +1599,7 @@ static ssize_t enabled_show(struct device *dev,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
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);
+ bool enabled;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
/* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
@@ -1590,7 +1607,10 @@ static ssize_t enabled_show(struct device *dev,
return -ENODEV;
}
- return sysfs_emit(buf, "%s\n", drvdata->rgb_enabled ? "true" : "false");
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
+ enabled = drvdata->rgb_enabled;
+
+ return sysfs_emit(buf, "%s\n", enabled ? "true" : "false");
}
static DEVICE_ATTR_RW(enabled);
@@ -1626,7 +1646,7 @@ static ssize_t speed_store(struct device *dev, struct device_attribute *attr,
/* 0 is fastest, invert value for intuitive userspace speed */
speed = 20 - val;
- scoped_guard(spinlock_irqsave, &drvdata->profile_lock)
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
drvdata->rgb_speed = speed;
mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
@@ -1640,7 +1660,7 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
struct led_classdev *led_cdev = dev_get_drvdata(dev);
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);
- u8 speed = 20 - drvdata->rgb_speed;
+ u8 speed;
scoped_guard(spinlock_irqsave, &drvdata->registration_lock) {
/* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq context */
@@ -1648,6 +1668,9 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
return -ENODEV;
}
+ scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
+ speed = 20 - drvdata->rgb_speed;
+
return sysfs_emit(buf, "%u\n", speed);
}
static DEVICE_ATTR_RW(speed);
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 4/8] HID: hid-msi: Re-init on reset during resume
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
` (2 preceding siblings ...)
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 ` 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
` (3 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark, stable
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.
Register msi_reset_resume and mark that resume as a resync so cfg_setup
re-reads the gamepad mode and the RGB profile. The flag clears only once
both reads complete, so a re-read cut short by another suspend is
retried.
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.
Fixes: a9517958e828 ("HID: hid-msi: Add MSI Claw configuration driver")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 44 +++++++++++++++++++++++++++++++++++--------
1 file changed, 36 insertions(+), 8 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index c7b7399ef930..606ff7d65276 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -345,6 +345,7 @@ struct claw_drvdata {
u8 waiting_cmd;
int cmd_status;
u16 bcd_device;
+ bool resync; /* Re-read MCU state, set on resume after a device reset */
u8 ep;
/* Gamepad Variables */
@@ -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);
+
scoped_guard(spinlock_irqsave, &drvdata->registration_lock)
/* Pairs with smp_store_release from below */
gp_registered = smp_load_acquire(&drvdata->gp_registered);
@@ -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_store_release 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));
}
@@ -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;
}
-static int msi_resume(struct hid_device *hdev)
+static int msi_resume_common(struct hid_device *hdev, bool resync)
{
int ret;
u8 ep;
@@ -2027,11 +2044,21 @@ static int msi_resume(struct hid_device *hdev)
ep = ret;
if (ep == CLAW_XINPUT_CFG_INTF_IN || ep == CLAW_DINPUT_CFG_INTF_IN)
- return claw_resume(hdev);
+ return claw_resume(hdev, resync);
return 0;
}
+static int msi_resume(struct hid_device *hdev)
+{
+ return msi_resume_common(hdev, false);
+}
+
+static int msi_reset_resume(struct hid_device *hdev)
+{
+ return msi_resume_common(hdev, true);
+}
+
static int claw_suspend(struct hid_device *hdev)
{
struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
@@ -2079,6 +2106,7 @@ static struct hid_driver msi_driver = {
.probe = msi_probe,
.remove = msi_remove,
.resume = pm_ptr(msi_resume),
+ .reset_resume = pm_ptr(msi_reset_resume),
.suspend = pm_ptr(msi_suspend),
};
module_hid_driver(msi_driver);
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 4/8] HID: hid-msi: Re-init on reset during resume
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
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-04 0:37 UTC (permalink / raw)
To: Derek J. Clark; +Cc: linux-input, linux-usb, dmitry.torokhov
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
` (3 preceding siblings ...)
2026-12-04 0:18 ` [PATCH 4/8] HID: hid-msi: Re-init on reset during resume Derek J. Clark
@ 2026-12-04 0:18 ` 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
` (2 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark, stable
Four write paths upstream end with SYNC_TO_ROM, a command sent with no
timeout, so the MCU can still owe an ACK at any moment. Suspend only
cancelled work items. A store issued against the suspending interface
armed a command, waited its full 25 ms and returned -EBUSY, the same
code a missing reply used, and a profile sequence could be cut between
two reports, leaving the MCU working copy and the driver cache
describing different profiles.
Gate commands on a suspended flag. Suspend and resume take rom_mutex
along with it, so a write sequence is indivisible with respect to the
transition, and the 500 ms the driver already documents for the MCU to
come back is now enforced. Commands fail until cfg_resume_fn opens the
gate. A missing reply reports -ETIMEDOUT, since -EBUSY now means
suspended. Suspend waits out an outstanding orphan ACK so no reply
expectation is carried across the transition. That wait covers an ACK
the MCU gives straight away. A device that answers a commit only when
the flash write finishes runs past it.
Fixes: a9517958e828 ("HID: hid-msi: Add MSI Claw configuration driver")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index 606ff7d65276..d6134ff310f3 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -344,6 +344,7 @@ struct claw_drvdata {
spinlock_t cmd_lock; /* Lock for cmd data read/write */
u8 waiting_cmd;
int cmd_status;
+ bool suspended;
u16 bcd_device;
bool resync; /* Re-read MCU state, set on resume after a device reset */
u8 ep;
@@ -576,6 +577,9 @@ static int __claw_hw_output_report(struct hid_device *hdev, u8 index, u8 *data,
lockdep_assert_held(&drvdata->cfg_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
/* If expecting an orphan ack, hold next event until MCU has time to clear it */
scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
orphaned = drvdata->orphan_ack_pending;
@@ -627,7 +631,7 @@ static int __claw_hw_output_report(struct hid_device *hdev, u8 index, u8 *data,
msecs_to_jiffies(timeout));
dev_dbg(&hdev->dev, "Remaining timeout: %u\n", ret);
- ret = ret > 0 ? drvdata->cmd_status : ret ?: -EBUSY;
+ ret = ret > 0 ? drvdata->cmd_status : ret ?: -ETIMEDOUT;
if (ret)
goto err;
}
@@ -877,6 +881,8 @@ static ssize_t apply_store(struct device *dev, struct device_attribute *attr,
flush_delayed_work(&drvdata->rgb_queue);
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
if (ret)
@@ -948,6 +954,9 @@ static int claw_mkey_store(struct device *dev, const char *buf, u8 mkey)
set_buttons:
scoped_guard(mutex, &drvdata->rom_mutex) {
+ if (drvdata->suspended)
+ return -EBUSY;
+
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
if (ret)
@@ -1077,6 +1086,9 @@ static ssize_t rumble_intensity_left_store(struct device *dev,
report.intensity = val;
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
if (ret)
@@ -1142,6 +1154,9 @@ static ssize_t rumble_intensity_right_store(struct device *dev,
report.intensity = val;
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
if (ret)
@@ -1290,6 +1305,9 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata)
}
guard(mutex)(&drvdata->rom_mutex);
+ if (drvdata->suspended)
+ return -EBUSY;
+
/* Loop through (up to) 8 pages of RGB data */
for (f = 0; f < drvdata->rgb_frame_count; f++) {
scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
@@ -1818,6 +1836,10 @@ static void cfg_resume_fn(struct work_struct *work)
struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, cfg_resume);
bool gp_registered, rgb_registered, resync;
+ scoped_guard(mutex, &drvdata->rom_mutex)
+ scoped_guard(mutex, &drvdata->cfg_mutex)
+ drvdata->suspended = false;
+
/* Pairs with smp_store_release from claw_resume in process context */
resync = smp_load_acquire(&drvdata->resync);
@@ -2027,7 +2049,7 @@ static int claw_resume(struct hid_device *hdev, bool resync)
smp_store_release(&drvdata->resync, true);
}
- /* MCU can take up to 500ms to be ready after resume */
+ /* Give the MCU time to come back, cfg_resume_fn clears the gate */
schedule_delayed_work(&drvdata->cfg_resume, msecs_to_jiffies(500));
return 0;
}
@@ -2062,6 +2084,7 @@ static int msi_reset_resume(struct hid_device *hdev)
static int claw_suspend(struct hid_device *hdev)
{
struct claw_drvdata *drvdata = hid_get_drvdata(hdev);
+ bool orphaned;
if (!drvdata)
return -ENODEV;
@@ -2070,6 +2093,22 @@ static int claw_suspend(struct hid_device *hdev)
cancel_delayed_work_sync(&drvdata->cfg_setup);
cancel_delayed_work_sync(&drvdata->rgb_queue);
+ guard(mutex)(&drvdata->rom_mutex);
+ guard(mutex)(&drvdata->cfg_mutex);
+ drvdata->suspended = true;
+
+ scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
+ orphaned = drvdata->orphan_ack_pending;
+
+ if (orphaned) {
+ if (!wait_for_completion_timeout(&drvdata->orphan_ack_complete,
+ msecs_to_jiffies(25)))
+ dev_dbg(&hdev->dev, "Timed out waiting for orphan ACK\n");
+
+ scoped_guard(spinlock_irqsave, &drvdata->cmd_lock)
+ drvdata->orphan_ack_pending = false;
+ }
+
return 0;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend
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
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-04 0:38 UTC (permalink / raw)
To: Derek J. Clark; +Cc: linux-input, linux-usb, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] HID: hid-msi: apply_store() races with claw_suspend() and
cfg_resume_fn()
- [Medium] HID: hid-msi: cfg_resume_fn() clears suspended gate before
reset resync
- [Low] HID: hid-msi: commit message describes pre-series SYNC_TO_ROM
paths
--
commit 4d5656ee486cb7868f5c825b51fb8126a0c79c11
Author: Derek J. Clark <derekjohn.clark@gmail.com>
HID: hid-msi: Drain in-flight MCU traffic before suspend
This commit gates MCU commands on a suspended flag protected by rom_mutex
and cfg_mutex, changes command timeouts to return -ETIMEDOUT instead of
-EBUSY, and waits for any pending orphan ACK during suspend.
> Four write paths upstream end with SYNC_TO_ROM, a command sent with no
> timeout, so the MCU can still owe an ACK at any moment.
[Severity: Low]
Is this opening sentence still accurate after commit "HID: hid-msi: Move the
ROM commit to an explicit apply attribute" earlier in this series? That
commit removed CLAW_COMMAND_TYPE_SYNC_TO_ROM from the four write paths,
leaving apply_store() as the only caller that sends it.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index 606ff7d652766..d6134ff310f3a 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> @@ -877,6 +881,8 @@ static ssize_t apply_store(struct device *dev, struct device_attribute *attr,
> flush_delayed_work(&drvdata->rgb_queue);
>
> guard(mutex)(&drvdata->rom_mutex);
> + if (drvdata->suspended)
> + return -EBUSY;
>
> ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
> if (ret)
[Severity: Medium]
Can apply_store() commit stale MCU RAM to flash by racing with
claw_suspend() or cfg_resume_fn()?
claw_suspend() cancels rgb_queue before taking rom_mutex and setting
drvdata->suspended = true. During USB autosuspend while userspace is still
running, a concurrent apply_store() can slip in between the cancel and the
flag update:
CPU0 (claw_suspend) CPU1 (apply_store)
cancel_delayed_work_sync(rgb_queue)
flush_delayed_work(rgb_queue) (no-op)
mutex_lock(&rom_mutex)
drvdata->suspended == false
CLAW_COMMAND_TYPE_SYNC_TO_ROM
<-- commits stale MCU RAM to flash
mutex_lock(&rom_mutex)
drvdata->suspended = true
A similar race happens on resume: if apply_store() flushes rgb_queue while
drvdata->suspended is still true, claw_write_rgb_state() aborts with -EBUSY,
which flush_delayed_work() does not report back. If cfg_resume_fn() then
clears drvdata->suspended before apply_store() takes rom_mutex,
apply_store() sends SYNC_TO_ROM on stale MCU RAM and returns success.
Setting drvdata->suspended under the mutexes before cancelling rgb_queue
(after releasing the mutexes to avoid an ABBA deadlock) and checking under
rom_mutex that no RGB update failed or remains pending would close both
windows.
[ ... ]
> @@ -1818,6 +1836,10 @@ static void cfg_resume_fn(struct work_struct *work)
> struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, cfg_resume);
> bool gp_registered, rgb_registered, resync;
>
> + scoped_guard(mutex, &drvdata->rom_mutex)
> + scoped_guard(mutex, &drvdata->cfg_mutex)
> + drvdata->suspended = false;
> +
> /* Pairs with smp_store_release from claw_resume in process context */
> resync = smp_load_acquire(&drvdata->resync);
[Severity: Medium]
Should cfg_resume_fn() keep drvdata->suspended set until the post-reset
resync in cfg_setup_fn() completes?
On a reset-resume, cfg_resume_fn() clears drvdata->suspended at T+500 ms and
then schedules cfg_setup for another 500 ms later. Because gp_registered
stays true across suspend, a userspace store to gamepad_mode_store() or
mkeys_function_store() during that 500 ms window passes the suspended check
in __claw_hw_output_report(), combines the new value with the stale
pre-reset cached peer field in claw_switch_mode(), and overwrites the MCU
state before cfg_setup_fn() reads it back.
Keeping userspace writes gated until cfg_setup_fn() finishes resyncing (for
instance by letting internal resync reads bypass the gate) would prevent
writes from running against stale cached state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204001846.3801336-1-derekjohn.clark@gmail.com?part=5
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
` (4 preceding siblings ...)
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:18 ` 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:18 ` [PATCH 8/8] USB: core: quirks: Add RESET_RESUME quirk for MSI Claw Derek J. Clark
7 siblings, 1 reply; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark, stable
An RGB update while the MCU is suspended, or still coming back after
resume, is rejected with -EBUSY and lost. The sysfs store has already
committed the new value, so it reports a setting the MCU never got.
Mark the RGB state dirty when an update is scheduled and clear it once
claw_write_rgb_state has written every frame. Clearing it while the
report is composed loses the update. The suspend gate sits after
composition, so the state is marked clean and then never sent. A dirty
state is replayed on resume. claw_rgb_schedule takes no mutex, so the
LED path stays non-blocking. cfg_setup_fn skips the RGB read-back while
state is pending, since the read would overwrite a newer change.
Fixes: f27e2e3c80ed ("HID: hid-msi: Add RGB control interface")
Cc: stable@vger.kernel.org
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/hid/hid-msi.c | 49 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 42 insertions(+), 7 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index d6134ff310f3..d2cd0d7397aa 100644
--- a/drivers/hid/hid-msi.c
+++ b/drivers/hid/hid-msi.c
@@ -372,6 +372,7 @@ struct claw_drvdata {
bool rgb_registered;
u8 rgb_frame_count;
bool rgb_enabled;
+ bool rgb_dirty; /* State held by the driver that the MCU has not taken */
u8 rgb_speed;
u16 rgb_addr;
};
@@ -1319,13 +1320,19 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata)
/* Serialize the rgb_report and write it to MCU */
ret = claw_hw_output_report(drvdata->hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
(u8 *)&report, sizeof(report), 25);
- if (ret)
+ if (ret) {
+ /* Pairs with smp_load_acquire from cfg_resume_fn. */
+ smp_store_release(&drvdata->rgb_dirty, true);
return ret;
+ }
/* Increment the write addr by the offset for the next frame */
write_addr += CLAW_RGB_FRAME_OFFSET;
}
+ /* Pairs with smp_load_acquire from cfg_resume_fn */
+ smp_store_release(&drvdata->rgb_dirty, false);
+
return 0;
}
@@ -1513,10 +1520,18 @@ static void claw_rgb_queue_fn(struct work_struct *work)
}
ret = claw_apply_rgb_state(drvdata);
- if (ret)
+ if (ret && ret != -EBUSY)
dev_err(&drvdata->hdev->dev, "Failed to apply RGB state: %d\n", ret);
}
+static void claw_rgb_schedule(struct claw_drvdata *drvdata)
+{
+ /* Pairs with the loads in cfg_resume_fn and cfg_setup_fn */
+ smp_store_release(&drvdata->rgb_dirty, true);
+
+ mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+}
+
static ssize_t effect_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
@@ -1539,7 +1554,7 @@ static ssize_t effect_store(struct device *dev,
scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
drvdata->rgb_effect = ret;
- mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ claw_rgb_schedule(drvdata);
return count;
}
@@ -1607,7 +1622,7 @@ static ssize_t enabled_store(struct device *dev,
scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
drvdata->rgb_enabled = val;
- mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ claw_rgb_schedule(drvdata);
return count;
}
@@ -1668,7 +1683,7 @@ static ssize_t speed_store(struct device *dev, struct device_attribute *attr,
scoped_guard(spinlock_irqsave, &drvdata->frame_lock)
drvdata->rgb_speed = speed;
- mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ claw_rgb_schedule(drvdata);
return count;
}
@@ -1713,7 +1728,7 @@ static void claw_led_brightness_set(struct led_classdev *led_cdev,
return;
}
- mod_delayed_work(system_dfl_wq, &drvdata->rgb_queue, msecs_to_jiffies(50));
+ claw_rgb_schedule(drvdata);
}
static struct attribute *claw_rgb_attrs[] = {
@@ -1750,6 +1765,7 @@ static void cfg_setup_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_setup);
bool gamepad_ready = false, rgb_ready = false, gp_registered, rgb_registered;
+ bool dirty;
int ret;
ret = claw_hw_output_report(drvdata->hdev, CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE,
@@ -1762,6 +1778,13 @@ static void cfg_setup_fn(struct work_struct *work)
gamepad_ready = true;
prep_rgb:
+ /* Pairs with smp_store_release from claw_rgb_schedule */
+ dirty = smp_load_acquire(&drvdata->rgb_dirty);
+ if (dirty) {
+ rgb_ready = true;
+ goto try_gamepad;
+ }
+
ret = claw_read_rgb_config(drvdata->hdev);
if (ret) {
dev_err(&drvdata->hdev->dev,
@@ -1828,13 +1851,20 @@ static void cfg_setup_fn(struct work_struct *work)
kobject_uevent(&drvdata->hdev->dev.kobj, KOBJ_CHANGE);
if (rgb_registered)
kobject_uevent(&drvdata->led_mc.led_cdev.dev->kobj, KOBJ_CHANGE);
+
+ if (rgb_ready) {
+ /* Pairs with smp_store_release from claw_rgb_schedule */
+ dirty = smp_load_acquire(&drvdata->rgb_dirty);
+ if (dirty)
+ claw_rgb_schedule(drvdata);
+ }
}
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;
+ bool gp_registered, rgb_registered, resync, rgb_dirty;
scoped_guard(mutex, &drvdata->rom_mutex)
scoped_guard(mutex, &drvdata->cfg_mutex)
@@ -1843,6 +1873,9 @@ static void cfg_resume_fn(struct work_struct *work)
/* Pairs with smp_store_release from claw_resume in process context */
resync = smp_load_acquire(&drvdata->resync);
+ /* Pairs with smp_store_release from claw_rgb_schedule. */
+ rgb_dirty = smp_load_acquire(&drvdata->rgb_dirty);
+
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);
@@ -1852,6 +1885,8 @@ static void cfg_resume_fn(struct work_struct *work)
if (resync || !gp_registered || !rgb_registered)
schedule_delayed_work(&drvdata->cfg_setup, msecs_to_jiffies(500));
+ else if (rgb_dirty)
+ claw_rgb_schedule(drvdata);
}
static void claw_features_supported(struct claw_drvdata *drvdata)
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended
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
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-04 0:32 UTC (permalink / raw)
To: Derek J. Clark; +Cc: linux-input, linux-usb, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] HID: hid-msi: unconditional rgb_dirty clear in
claw_write_rgb_state()
- [Medium] HID: hid-msi: TOCTOU race in cfg_setup_fn() overwrites
concurrent RGB updates
- [Medium] HID: hid-msi: apply_store() commits stale MCU RAM while
rgb_dirty is pending
--
commit bff64a28bf114d7d4e680c8a15718af9d92745dc
Author: Derek J. Clark <derekjohn.clark@gmail.com>
HID: hid-msi: Defer RGB updates while the MCU is suspended
This patch adds an rgb_dirty flag to struct claw_drvdata so RGB updates
scheduled while the MCU is suspended are tracked, replayed on resume, and
not overwritten by cfg_setup_fn() reading back MCU state.
> diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
> index d6134ff310f3a..d2cd0d7397aa4 100644
> --- a/drivers/hid/hid-msi.c
> +++ b/drivers/hid/hid-msi.c
[ ... ]
> @@ -1319,13 +1320,19 @@ static int claw_write_rgb_state(struct claw_drvdata *drvdata)
> /* Serialize the rgb_report and write it to MCU */
> ret = claw_hw_output_report(drvdata->hdev, CLAW_COMMAND_TYPE_WRITE_PROFILE_DATA,
> (u8 *)&report, sizeof(report), 25);
> - if (ret)
> + if (ret) {
> + /* Pairs with smp_load_acquire from cfg_resume_fn. */
> + smp_store_release(&drvdata->rgb_dirty, true);
> return ret;
> + }
>
> /* Increment the write addr by the offset for the next frame */
> write_addr += CLAW_RGB_FRAME_OFFSET;
> }
>
> + /* Pairs with smp_load_acquire from cfg_resume_fn */
> + smp_store_release(&drvdata->rgb_dirty, false);
> +
> return 0;
> }
[Severity: Medium]
Can this unconditional clear of drvdata->rgb_dirty drop a newer RGB update
that arrived while claw_write_rgb_state() was transmitting an earlier one?
Because the RGB sysfs stores and claw_led_brightness_set() do not take
rom_mutex, a new update can set rgb_dirty and re-arm rgb_queue while an
in-flight claw_write_rgb_state() is still sending frames for an older
snapshot:
CPU0 (claw_rgb_queue_fn) CPU1 (effect_store / claw_suspend)
claw_apply_rgb_state()
claw_write_rgb_state()
write frames for update A
drvdata->rgb_effect = B
claw_rgb_schedule()
rgb_dirty = true
mod_delayed_work(..., 50ms)
rgb_dirty = false <-- clears dirty for update B
claw_suspend()
cancel_delayed_work_sync(&rgb_queue)
If suspend runs before the re-armed work completes, rgb_queue is cancelled
with rgb_dirty already cleared (and if update B already blocked on
rom_mutex, the drvdata->suspended check in claw_write_rgb_state() returns
-EBUSY without re-marking rgb_dirty). On resume, cfg_resume_fn() sees
rgb_dirty as false and never replays update B, leaving sysfs out of sync
with the MCU.
Tracking a monotonic generation counter incremented in claw_rgb_schedule(),
snapshotted before reading RGB state in claw_apply_rgb_state(), and only
clearing rgb_dirty when the generation still matches after all frames
succeed would avoid clobbering concurrent updates.
[ ... ]
> @@ -1762,6 +1778,13 @@ static void cfg_setup_fn(struct work_struct *work)
> gamepad_ready = true;
>
> prep_rgb:
> + /* Pairs with smp_store_release from claw_rgb_schedule */
> + dirty = smp_load_acquire(&drvdata->rgb_dirty);
> + if (dirty) {
> + rgb_ready = true;
> + goto try_gamepad;
> + }
> +
> ret = claw_read_rgb_config(drvdata->hdev);
> if (ret) {
> dev_err(&drvdata->hdev->dev,
[Severity: Medium]
Can an RGB update that arrives during claw_read_rgb_config() still be
overwritten by stale MCU data?
After a reset-resume, cfg_resume_fn() clears drvdata->suspended and
schedules cfg_setup_fn() while rgb_registered is already true.
cfg_setup_fn() checks rgb_dirty only once before claw_read_rgb_config()
sends 8 sequential read reports under profile_mutex:
CPU0 (cfg_setup_fn) CPU1 (speed_store / HID irq)
dirty = rgb_dirty /* false */
claw_read_rgb_config()
send READ_PROFILE frame 0
drvdata->rgb_speed = new_speed
claw_rgb_schedule()
rgb_dirty = true
claw_profile_event()
drvdata->rgb_speed = mcu_speed <-- lost
...
dirty = rgb_dirty /* true */
claw_rgb_schedule() <-- replays clobbered MCU values
claw_profile_event() acquires frame_lock without checking rgb_dirty and
overwrites rgb_frames[], rgb_speed, brightness, and subled_info with the
MCU reply, which cfg_setup_fn() then schedules to be written back. Also,
because claw_read_rgb_config() does not hold rom_mutex, claw_rgb_queue_fn()
can fire mid-read and transmit a mix of old MCU frames and newly composed
frames.
[ ... ]
> @@ -1843,6 +1873,9 @@ static void cfg_resume_fn(struct work_struct *work)
> /* Pairs with smp_store_release from claw_resume in process context */
> resync = smp_load_acquire(&drvdata->resync);
>
> + /* Pairs with smp_store_release from claw_rgb_schedule. */
> + rgb_dirty = smp_load_acquire(&drvdata->rgb_dirty);
> +
> 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);
> @@ -1852,6 +1885,8 @@ static void cfg_resume_fn(struct work_struct *work)
>
> if (resync || !gp_registered || !rgb_registered)
> schedule_delayed_work(&drvdata->cfg_setup, msecs_to_jiffies(500));
> + else if (rgb_dirty)
> + claw_rgb_schedule(drvdata);
> }
[Severity: Medium]
Can apply_store() commit stale or partially-written MCU RAM to ROM while
rgb_dirty is pending?
apply_store() only flushes rgb_queue and checks drvdata->suspended before
issuing CLAW_COMMAND_TYPE_SYNC_TO_ROM:
drivers/hid/hid-msi.c:apply_store() {
...
flush_delayed_work(&drvdata->rgb_queue);
guard(mutex)(&drvdata->rom_mutex);
if (drvdata->suspended)
return -EBUSY;
ret = claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_SYNC_TO_ROM, NULL, 0, 0);
...
}
When resync is true, cfg_resume_fn() clears drvdata->suspended and
schedules cfg_setup for 500 ms later without queuing rgb_queue, leaving a
500 ms window where suspended is false, rgb_dirty is true, and rgb_queue is
idle. A mid-loop write error in claw_write_rgb_state() similarly leaves
rgb_dirty true with rgb_queue idle and partial frames in MCU RAM. Writing
1 to apply in either state makes flush_delayed_work() a no-op and flashes
the stale or torn MCU RAM to ROM while reporting success.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204001846.3801336-1-derekjohn.clark@gmail.com?part=6
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 7/8] HID: hid-msi: Switch the RGB LED to brightness_set_blocking
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
` (5 preceding siblings ...)
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:18 ` 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
7 siblings, 1 reply; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark
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>
---
drivers/hid/hid-msi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c
index d2cd0d7397aa..f4b592c7d297 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);
+
claw_rgb_schedule(drvdata);
+
+ return 0;
}
static struct attribute *claw_rgb_attrs[] = {
@@ -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;
drvdata->led_mc.num_colors = 3;
drvdata->led_mc.subled_info = devm_kmemdup(&hdev->dev, claw_rgb_subled_info,
sizeof(claw_rgb_subled_info), GFP_KERNEL);
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* Re: [PATCH 7/8] HID: hid-msi: Switch the RGB LED to brightness_set_blocking
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
0 siblings, 0 replies; 14+ messages in thread
From: sashiko-bot @ 2026-12-04 0:39 UTC (permalink / raw)
To: Derek J. Clark; +Cc: linux-input, linux-usb, dmitry.torokhov
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 8/8] USB: core: quirks: Add RESET_RESUME quirk for MSI Claw
2026-12-04 0:18 [PATCH 0/8] MSI Claw suspend, resume and ROM commit fixes Derek J. Clark
` (6 preceding siblings ...)
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:18 ` Derek J. Clark
7 siblings, 0 replies; 14+ messages in thread
From: Derek J. Clark @ 2026-12-04 0:18 UTC (permalink / raw)
To: jikos, bentiss
Cc: linux-input, kernel, gregkh, linux-usb, pgriffais,
derekjohn.clark
The Claw does not come back after a system resume and rebinding the HID
driver does not recover it. Resetting the usb_device does, so add
USB_QUIRK_RESET_RESUME for the four product IDs.
The quirk is device-wide. In xinput mode xpad holds a vendor-specific
interface with no reset_resume, so the core unbinds and rebinds it on
each resume and runtime suspend is refused.
Tested on a Claw A8 with usbcore.quirks=0db0:1902:b before the entry
went into the table.
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/usb/core/quirks.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index a4bcbe9c913c..c0852582fa49 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -469,6 +469,12 @@ static const struct usb_device_id usb_quirk_list[] = {
{ USB_DEVICE(0x0c45, 0x7056), .driver_info =
USB_QUIRK_IGNORE_REMOTE_WAKEUP },
+ /* MSI Claw does not restore its USB state on resume */
+ { USB_DEVICE(0x0db0, 0x1901), .driver_info = USB_QUIRK_RESET_RESUME },
+ { USB_DEVICE(0x0db0, 0x1902), .driver_info = USB_QUIRK_RESET_RESUME },
+ { USB_DEVICE(0x0db0, 0x1903), .driver_info = USB_QUIRK_RESET_RESUME },
+ { USB_DEVICE(0x0db0, 0x1904), .driver_info = USB_QUIRK_RESET_RESUME },
+
/* Elgato 4K X - BOS descriptor fetch hangs at SuperSpeed Plus */
{ USB_DEVICE(0x0fd9, 0x009b), .driver_info = USB_QUIRK_NO_BOS },
--
2.56.0
^ permalink raw reply related [flat|nested] 14+ messages in thread