From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796088323; b=YKKitIfpP9FvJvDXfsWNa91PE13uZuLlmZStQBl82lOccVCNKnqAU/+3uCtKD9gad5k7 JVApujJCTnQmt1l5fA5cO4F6GEpwvltSfXLtK7w/RFtoltq+l14vA2/lJ5XPx4HqGrWB4 SkbA7cG7AagrfIhOSU/xxme4bhiuRnX8DrHzGMldQ8vgzjSCc1CHHR6eunZSbiJ6NdbLo 6x4d4h73n9tQRbZ0uD/GR5VCYMBinrYpUVWlx+Fgc3endPaW051VDZ2ZoWqGKYA5lAE4a WjqSc9K1B5C0EMshqwd+w5xD2Q+gtPN9xvioi5t5+qRiiwAnskK0SoBV8ngw1rqT/Ww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796088323; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Fi7cDtJKbAdWnCnH6vs3ZSrbhLIKhpod8dqhrBnwpjw=; b=bXARwkkxBbwAcpmrDPfDtf3gRN8CzLy93uiByrp40HpqxBHO2je2E+zd/b6dbY6yBXXX Dg+BOBoitp86/kBcoyWSG1lIOYLP3dwBKwyZmVJm9HdFCK+ZqddN7thiwZyjGsE1kSPrw PjWbdS/jjqfQfuZfLpL2VlssW7vRJbheySuZyJ5fftZqDG+q056eyDH0aQ75usyvPgGgF RoEKkhuf6VBM4HMqJmbgK/V3WnmR/5w1LK+FW8gAjkmPIqQZHQI7OWYnQ7dz6TryFzZ+o 4ti60NR7PC+Ep/v4N5CCjVE3N3BgPy77lcIrw5SetMrBGJkfAVx5UYgxbySkA8M1SdQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aAc9paKp; arc=none smtp.remote-ip=74.125.82.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AAD4606A31A for ; Tue, 1 Dec 2026 01:25:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3AAD4606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aAc9paKp Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1aefd1bf74aso6963872c88.1 for ; Mon, 30 Nov 2026 17:25:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796088322; x=1796693122; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Fi7cDtJKbAdWnCnH6vs3ZSrbhLIKhpod8dqhrBnwpjw=; b=aAc9paKp8qQfOTLXZwCTkO6BqnjqOpzZWrI+H2uIzBQbTLRiOaQEvXoqpp85riGgES CaKz1cuET29StZqrruJpXqSmi+A3alL0vzaLUDyvFmZjgBRJRw3TNamHvqnNLN3tCcCQ N6IzE7y+xvsjJDR4YcJSgl2S4jf9mD2oXs7DdrKlcbMiEg/aynrNdTYh4NJdN/Yp75Nw evpt5PnK4VEjLdc5JAF4O3Il4eCXf8fw1tLtjjv4OV+37WC3b2h8o0ZNhpzaIu0/5nPR WBlIosbRe6ImZaMtdxqpb2Wk1u11mbFRiRJtLkA92FHamwN6thQwY6WUjZ8Qpu2O4WtA oAFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796088322; x=1796693122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Fi7cDtJKbAdWnCnH6vs3ZSrbhLIKhpod8dqhrBnwpjw=; b=cXozCeC3snH3jfJtFWY5W8mr4oDh1XaB0WddzSvvEAw/UUgRhGv4dGeyLOQHfUvXNL gO0dxhd4Wp9shxG3TvOOwKzHO3dcX4fwFxNT1KGaF6b1lKLI1x9VK2UGl9yLceCdSr1S SKwgWKgMHyNVd8qPjzSwLw6VprK6s28GTggls5fXN2ttm2fHzZMmVDyIiq+KRCkFZrqy 6Hd/dSzx3Ll6GaE9AktvHaYIQI6qVBe2Zi4i3f4VHHQkuVZwcl3T1htbzylwXXKTFIMi 7jSsUYVHR0vtsZBdgAxunxuRZVpOW9EEEgcjgY409o12xgc5LEwA5H53IE5+3rRAGxtA rEIA== X-Gm-Message-State: APuU4Z8N5bOKSQ746+ikO6zWwPsjHgrXee6XdWoSrpk15e/bqXZnQZCp aJRU5n+1igQah9P13q+nzEVTNnbxHi7FkY5Wk0ua3R3NlduFH1OrvhNm X-Gm-Gg: AZFdTZdLm+GZ/fH0WTKwvIfkv/r9Lb6N+gdmWQCOho9vtTdFftDSLOuabtRVgQQGqAx d68RJky1Qj9lWkdacknVnwdiN21xEVHpd3DytKIRAGnq1K9qdMT7Lh8Wnv8JcW2P5yrEiOL39nA mvHK23JZqiaEAkZ6Bij2eTb0ccuM3roXUBne2aN6neUt50DWksTLXEmHyY/5+/hddNdf1nlKIPm H0K7e+jLh/+FrIAsy30NtoCnZlRpcSL8CKL2G9DnriDit+0i//HkyDQkIoQZ2n9pEJ++S8tvaQm 4ghv8YTKaVsvCjiVLbvzPBNUgE+ydqsw9vGvMD+ACkyxZZC4qSZYeaN3mixH2D19lY5RStzyBlC 6x0bBYk1u6Oov3zTzKXbIh4EsAJ5sgMKHGab4PtBgRPx+qoW2ubyG5RQosYsWXYok0Gk3DY9KxC OnEm8+qB4ZWtvhhrqBiO+msxC0sfoaKzLpO7U9xN7L+m2CNOILFQghuLSstDy5EN5km9ICwzBf3 gPPRSQg9zeFjJ3YZHn4wsVHblZYvk1/2FCj9eoyASN3yga+TD1wP6H165JaUJXry3GtEGzRLveA 9OiIebIPAD8dcauTFv0YquKDNs7xTc8l2BsQXVUyJH3yzwuwD13sNrsj9xc5pRu3+NcBKMbGuzX 8v9aAmUaeI6vX4/gV+HmuXCkwJXkIOQ== X-Received: by 2002:a05:701b:4213:10b0:185:6c8c:d860 with SMTP id a92af1059eb24-1b5568aac8emr33908941c88.5.1796088322192; Mon, 30 Nov 2026 17:25:22 -0800 (PST) Received: from lappy.taila8a9bd.ts.net (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b55684c85fsm124655117c88.14.2026.11.30.17.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 17:25:21 -0800 (PST) From: "Derek J. Clark" To: Ana Veto Cc: linux-input@vger.kernel.org, Jiri Kosina , Benjamin Tissoires , Kenhou Iijima Subject: Re: [PATCH v5] HID: hid-msi: Send a uevent when the MCU changes the mode by itself Date: Mon, 30 Nov 2026 17:25:17 -0800 Message-ID: <20261201012520.2314069-1-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261117132448.57489-1-green.koala2979@fastmail.com> References: <20261117132448.57489-1-green.koala2979@fastmail.com> X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, 17 Nov 2026, Ana Veto wrote: > Emit KOBJ_CHANGE from a work item whenever a report changes the stored > mode or M-key function. Ana, v5 is close, I just have one issue. Holding View+LB is the user asking for that mode, so we should be respecting user choice rather than spamming userspace with uevents. The risk of the bug as it is now is that userspace never returns to the previous state when the action is done being held. I think it would be preferable to wait for the event storm to settle before triggering the uevent to return to the pre-held state. Using a mod_delayed_work ensures only the last event triggers. I'm thinking something close to this: <8> --- drivers/hid/hid-msi.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) --- a/drivers/hid/hid-msi.c +++ b/drivers/hid/hid-msi.c @@ -350,7 +350,8 @@ /* Gamepad Variables */ enum claw_mkeys_function_index mkeys_function; enum claw_gamepad_mode_index gamepad_mode; - struct work_struct mode_event; /* uevent when the MCU changes the mode */ + struct delayed_work mode_event; /* uevent when the MCU changes the mode */ + bool mode_event_owed; /* Change owed to userspace, guarded by mode_lock */ unsigned int mode_reports; /* Mode reports stored, guarded by mode_lock */ u8 m1_codes[CLAW_KEYS_MAX]; u8 m2_codes[CLAW_KEYS_MAX]; @@ -391,7 +392,15 @@ static void claw_mode_event_fn(struct work_struct *work) { - struct claw_drvdata *drvdata = container_of(work, struct claw_drvdata, mode_event); + struct delayed_work *dwork = container_of(work, struct delayed_work, work); + struct claw_drvdata *drvdata = container_of(dwork, struct claw_drvdata, mode_event); + + /* The timer can also run out on reports that changed nothing. */ + scoped_guard(spinlock_irqsave, &drvdata->mode_lock) { + if (!drvdata->mode_event_owed) + return; + drvdata->mode_event_owed = false; + } kobject_uevent(&drvdata->hdev->dev.kobj, KOBJ_CHANGE); } @@ -401,7 +410,8 @@ guard(spinlock_irqsave)(&drvdata->registration_lock); /* Pairs with smp_store_release from cfg_setup_fn and claw_remove */ if (smp_load_acquire(&drvdata->gp_registered)) - schedule_work(&drvdata->mode_event); + mod_delayed_work(system_dfl_wq, &drvdata->mode_event, + msecs_to_jiffies(2100)); } static int claw_gamepad_mode_event(struct claw_drvdata *drvdata, @@ -420,10 +430,15 @@ drvdata->gamepad_mode = cmd_rep->data[0]; drvdata->mkeys_function = cmd_rep->data[1]; drvdata->mode_reports++; + if (changed) + drvdata->mode_event_owed = true; } - /* The MCU also changes the state by itself, e.g. on View+LB */ - if (changed) + /* The MCU also changes the state by itself, e.g. on View+LB. Any report + * it sends on its own pushes the event back. The caller holds cmd_lock + * for the waiting_cmd read. + */ + if (drvdata->waiting_cmd != CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE) claw_queue_mode_event(drvdata); return 0; @@ -723,7 +738,15 @@ /* A report during the transfer can be older or newer than the write */ if (raced) { - __claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE, NULL, 0, 25); + ret = __claw_hw_output_report(hdev, CLAW_COMMAND_TYPE_READ_GAMEPAD_MODE, + NULL, 0, 25); + if (ret) + dev_dbg(&hdev->dev, + "Failed to re-read the mode after a raced write: %d\n", ret); + + scoped_guard(spinlock_irqsave, &drvdata->mode_lock) + drvdata->mode_event_owed = true; + claw_queue_mode_event(drvdata); } @@ -1924,7 +1947,7 @@ INIT_DELAYED_WORK(&drvdata->cfg_resume, &cfg_resume_fn); INIT_DELAYED_WORK(&drvdata->cfg_setup, &cfg_setup_fn); INIT_DELAYED_WORK(&drvdata->rgb_queue, &claw_rgb_queue_fn); - INIT_WORK(&drvdata->mode_event, &claw_mode_event_fn); + INIT_DELAYED_WORK(&drvdata->mode_event, &claw_mode_event_fn); /* For control interface: open the HID transport for sending commands. */ ret = hid_hw_open(hdev); @@ -2001,7 +2024,7 @@ } /* gp_registered is false now, so no new mode event can be queued */ - cancel_work_sync(&drvdata->mode_event); + cancel_delayed_work_sync(&drvdata->mode_event); if (gp_registered) device_remove_group(&hdev->dev, &claw_gamepad_attr_group); Holding View+LB here gives a report every 2000 ms with a few tens of microseconds of jitter. The mode field does not move during it and the M-key function alternates between macro and disabled, which is what makes every report look like a change. 2100 ms produced no event at all while the keys stayed down and one event 2.1 s after the last report, so userspace sees the settled state once you let go. One other thing, this needs Kenhou's patch ahead of it. The re-read you add after a raced write is a READ_GAMEPAD_MODE, and SWITCH_MODE is sent with timeout 0 and can leave a second generic 0x06 behind. Without his guard that ACK completes the re-read early with cmd_status 0 and no payload, and the value the uevent just told userspace to fetch is the cached one. If you apply this on top for v6, please add these before your SOB: Co-developed-by: "Derek J. Clark" Signed-off-by: "Derek J. Clark" Thanks, Derek