From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796344330; b=c1jAI+/tumefqWAVpYFPeoYHGvkjWVpjK/GlSFgINGQD+A8Y8D+gocUKvgkL/kDAuVlB 3SaFNtoMlOfnu0BAB87mFE6apE5iGpxmjDlZlpcSia70i/BqFdY59Z3P0HlASb92zmiMc hwWcO7Gcy9+6LBi6CxcBqpG9d7DqhwFgIksF4oTwTL3/qmBU/Cs+Z4QfgcbXpVpDCfXHp 5t65DKg1tsXxywPuEERiNujN5sh2hjP/jP8bDPo01yonTlkjSbCeWC2dGCmSflqU/fhGx i/1DuQo9He6DDybvL53NH57ll744pLN+9obwlLzhS0ev0Vu1ZyionOWAJ/ThabKikWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344330; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=uDABr6dUtZ/ov+l4LKhmpIOZBayPVxPAxpkCUprOqFU=; b=VcerwghnkW7DB8tbWqFnMsNrr/vsirFohtkB9nCC+N0idFwTarMUunIS84NaUtIbjnks gIHEhC3AaC4d6u8ZzPU/kGJX0Xwdn1PH/RY5uFsGipNeezW1HVdrnXyYyUKYVEAjvCEVZ +OqEfC924bn8AfUoazVk/zTEnVEjVPk9fR2s7YUHup559Yenle1X/pvKtfoM9PtHK5/kl 5TFqItLnKe699XOOz9LpifX+a+VXfbi7eiYKaKmCK/jt4io3Y9ecB+LlqBLvEFTFSQ8vr Npl/2PTWN9Gd46P5kXUXYo1v3PIkbGA4y0Morgx05Y5tkJ/eCVmfeRnr7cjpbIZXCfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IE8pe+Rj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6365606A32C; Fri, 4 Dec 2026 00:32:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IE8pe+Rj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B8A71F000C2; Fri, 4 Dec 2026 00:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796344330; bh=uDABr6dUtZ/ov+l4LKhmpIOZBayPVxPAxpkCUprOqFU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=IE8pe+RjarWin2mkuOdSM7HpF0guBHCK26Hvc1ek+eaLj96s8eJ3jQtz9MwshvIJA MRQHl1H0BsTyA2MSqXKjkbrmCXODO+LOPeL610BO/urHDMmlY0r5B2XtXeSqVkhfxc Z3gKUbiA+P5GhWj/WFylT3/m0cH0CvySJ3i6hetrL9SNVwaenVSSiUKj2cz7KCqGGI TCwXA5l4maSdKdgskZ74h3EQ6X9u/zk5+2jLXLZltnM7x+PzL7B01CX+UylwKJSl8Z snAI0Sw5jVxePv0uRqp+Qr0PZmwuv99XKuVtEKuTXoZvC9iPnweEv1HTEqQ0gZy7n+ swudRcQncwp2Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 6/8] HID: hid-msi: Defer RGB updates while the MCU is suspended Reply-To: sashiko-reviews@lists.linux.dev To: "Derek J. Clark" Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261204001846.3801336-7-derekjohn.clark@gmail.com> References: <20261204001846.3801336-1-derekjohn.clark@gmail.com> <20261204001846.3801336-7-derekjohn.clark@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:32:10 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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_drvda= ta *drvdata) > /* Serialize the rgb_report and write it to MCU */ > ret =3D claw_hw_output_report(drvdata->hdev, CLAW_COMMAND_TYPE_WRITE_P= ROFILE_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; > + } > =20 > /* Increment the write addr by the offset for the next frame */ > write_addr +=3D CLAW_RGB_FRAME_OFFSET; > } > =20 > + /* 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 =3D B claw_rgb_schedule() rgb_dirty =3D true mod_delayed_work(..., 50ms) rgb_dirty =3D 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 =3D true; > =20 > prep_rgb: > + /* Pairs with smp_store_release from claw_rgb_schedule */ > + dirty =3D smp_load_acquire(&drvdata->rgb_dirty); > + if (dirty) { > + rgb_ready =3D true; > + goto try_gamepad; > + } > + > ret =3D 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 =3D rgb_dirty /* false */ claw_read_rgb_config() send READ_PROFILE frame 0 drvdata->rgb_speed =3D new_speed claw_rgb_schedule() rgb_dirty =3D true claw_profile_event() drvdata->rgb_speed =3D mcu_speed <-- l= ost ... dirty =3D 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 =3D smp_load_acquire(&drvdata->resync); > =20 > + /* Pairs with smp_store_release from claw_rgb_schedule. */ > + rgb_dirty =3D 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 =3D smp_load_acquire(&drvdata->gp_registered); > @@ -1852,6 +1885,8 @@ static void cfg_resume_fn(struct work_struct *work) > =20 > 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204001846.3801= 336-1-derekjohn.clark@gmail.com?part=3D6