Thread (6 messages) flat view 6 messages, 2 authors, 2d ago

Re: [PATCH v13 2/3] HID: nintendo: Add rumble support for Switch 2 controllers

From: sashiko-bot@kernel.org
Date: 2026-08-12 01:35:30

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Rumble workqueue catch-up loop causes extreme HID bus spam and delayed haptics.
--
--- Patch [2]: [PATCH v13 2/3] HID: nintendo: Add rumble support for Switch 2 controllers ---
commit 0c691726864354d8749a514212fbc109cdbf67d2
Author: Vicki Pfau [off-list ref]

HID: nintendo: Add rumble support for Switch 2 controllers
    
This adds rumble support for both the "HD Rumble" linear resonant actuator
type and eccentric rotating mass haptics used in Switch 2 controllers. It
adds a delayed workqueue to dispatch periodic rumble updates to the hardware.
quoted hunk ↗ jump to hunk
diff --git a/drivers/hid/hid-nintendo.c b/drivers/hid/hid-nintendo.c
index 78c9ad3c16104..4f58b6f9df38a 100644
--- a/drivers/hid/hid-nintendo.c
+++ b/drivers/hid/hid-nintendo.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -3209,6 +3263,128 @@ static void switch2_kref_put(struct kref *refcount)
[ ... ]
+static void switch2_rumble_work(struct work_struct *work)
+{
[ ... ]
+	if (active) {
+		unsigned long interval = msecs_to_jiffies(4);
+		uint64_t current_jiffies = get_jiffies_64();
+
+		if (!ns2->last_rumble_work)
+			ns2->last_rumble_work = current_jiffies;
+		else
+			ns2->last_rumble_work += interval;
+
+		/* Reschedule a little early to make sure the buffer never underruns */
+		interval -= msecs_to_jiffies(2);
+		if (ns2->last_rumble_work + interval >= current_jiffies)
+			schedule_delayed_work(&ns2->rumble_work,
+				ns2->last_rumble_work + interval - current_jiffies);
+		else
+			schedule_delayed_work(&ns2->rumble_work, 0);
[Severity: High]
Will this loop continuously without delay if switch2_rumble_work() falls
behind?

If CPU scheduling delays the worker or there is lock contention,
ns2->last_rumble_work might fall far behind current_jiffies. Because
ns2->last_rumble_work is only incremented by 4ms each run, the else branch
will reschedule the work with a 0 delay over and over until it catches up.

Can this spam the HID transport with stale synchronous commands and delay
input events, or cause haptics to continue playing long after the intended
effect stops?
+	} else {
+		ns2->last_rumble_work = 0;
+	}
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812012037.3251614-1-vi@endrift.com?part=2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help