* [PATCH 2/8] HID: hid-msi: Move the ROM commit to an explicit apply attribute
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
@ 2026-12-04 0:18 ` Derek J. Clark
2026-12-04 0:18 ` [PATCH 3/8] HID: hid-msi: Protect the RGB state with frame_lock Derek J. Clark
` (3 subsequent siblings)
4 siblings, 0 replies; 5+ 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] 5+ messages in thread
* [PATCH 3/8] HID: hid-msi: Protect the RGB state with frame_lock
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
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
` (2 subsequent siblings)
4 siblings, 0 replies; 5+ 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] 5+ messages in thread
* [PATCH 4/8] HID: hid-msi: Re-init on reset during resume
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
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 ` [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:18 ` [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend Derek J. Clark
2026-12-04 0:18 ` [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Derek J. Clark
4 siblings, 0 replies; 5+ 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] 5+ messages in thread
* [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
` (2 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:18 ` [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Derek J. Clark
4 siblings, 0 replies; 5+ 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] 5+ messages in thread
* [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
` (3 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
4 siblings, 0 replies; 5+ 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] 5+ messages in thread
end of thread, other threads:[~2026-12-04 0:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261204001846.3801336-1-derekjohn.clark@gmail.com>
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 ` [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:18 ` [PATCH 5/8] HID: hid-msi: Drain in-flight MCU traffic before suspend Derek J. Clark
2026-12-04 0:18 ` [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Derek J. Clark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox