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=1796344662; b=MqXES6MFvdUucAy+GFF1BlSsqmE0pH2Vcd2JY1BxWwvoH6LZ4dQ2YpFaOU3Nucr9xayZ RzjdfhkonIoXA+zWcrgX8+wkm5bXO9w6VfRjOcxuKSZzOtX0LJIKHNZDtFHyDO9DmVllM OfjIVncoiA3PTBYxjdB4MJR5jPoLLN+upRmGd3XQp9bjMInkbKxTfd18n2Sca8tCWynZL bDZi9e0m5t006vXz/PHl9WQW1WzzM43IEVNhqZdXm1wFbH60gsEI0jRodL2RFkI6aKjBg KlmDb7x8hevDHip2f7gZfL5o2RLf354HlZ2VrsYd1iQGcQzEK3z/wrA5kOMd1Mo/VOA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344662; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=KG/YVypbM5CUqznjzNCKe4L/7nUURY88hh5Xv/tF+8Q=; b=WrTewwOOK1fwJvpxgKhY02njI1yIBCh8AvM0TjCVwnTBs39x5u165iGMLnUQk9KAJbYf Lk5xvboEPW5D1PGEDUUoFwVyemUiYOJeIdFpOAvn7RaEPeGQYVL0iUvpdR7jXQA7J2+he 6vOvToofcZ1TGpOps4VivMHPVFEN6jZKIaKGXMkiYb/847Lo2ftGlHkmCoXWoyH+qdGUP oGQbAU7J23Yb8wYPNV9Or3JeG+rTTgGLNUjHWF7frcKzlj8c9WeoHI5I7s0QJNY53Ysar zeEsdo+FHv81Xk3LS7mqcRMy24BUFYMVcHh8fGexRxGoO7sGOgKd3j4nD+xr0J8D8lQ== 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=hk64Y+gn; 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 53078606A322; Fri, 4 Dec 2026 00:37:42 +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=hk64Y+gn Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4F4C1F000CE; Fri, 4 Dec 2026 00:37:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796344661; bh=KG/YVypbM5CUqznjzNCKe4L/7nUURY88hh5Xv/tF+8Q=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hk64Y+gnWz5D0Hlex+xdr1MmZ7pMKJBtXeHTPxpinIVdy5D5paJZUODSwZEz+0/iJ FLO91y/qACSo7cZP0YQ2vGy6Rv0Z007+YXA77NlZGJArPE7v/Vf8VLWBTqOH9Cykp9 JcmDiDMQWBt85mkJWq7XhUvFGGTN5YAPUei4GXA2FGMa3ZqE2qnAI2RA+/O+ONEN0k 9Dm2IgZdl6ol7nqPdlA1o4UeixZkaRQdcWT9nW3Hv2HnHmnmMM5yPVhTYj1vbHZqtE /Dp9R8R5DtokxFzOMSJv0EbVqlHE/tSvI8roOufP5gzuvB711msaiCeTth8tnVNh2B v2HLMyAj9C6HA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 4/8] HID: hid-msi: Re-init on reset during resume 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-5-derekjohn.clark@gmail.com> References: <20261204001846.3801336-1-derekjohn.clark@gmail.com> <20261204001846.3801336-5-derekjohn.clark@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:37:41 +0000 X-Mailing-List: linux-input@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 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 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) > =20 > /* 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=3D0 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 *wor= k) > { > struct delayed_work *dwork =3D container_of(work, struct delayed_work, = work); > struct claw_drvdata *drvdata =3D container_of(dwork, struct claw_drvdat= a, cfg_resume); > + bool gp_registered, rgb_registered, resync; > + > + /* Pairs with smp_load_acquire from claw_resume in process context */ > + resync =3D 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 =3D smp_load_acquire(&drvdata->gp_registered); > + /* Pairs with smp_store_release from cfg_setup_fn in system_percpu_wq = context */ > + rgb_registered =3D smp_load_acquire(&drvdata->rgb_registered); > + } > =20 > - 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 =3D ... subled_info[0..2].intensity =3D ... subled_info[0..2].intensity =3D ... <-- 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] =3D 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); > } > =20 > -static int claw_resume(struct hid_device *hdev) > +static int claw_resume(struct hid_device *hdev, bool resync) > { > struct claw_drvdata *drvdata =3D hid_get_drvdata(hdev); > =20 > if (!drvdata) > return -ENODEV; > =20 > + 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204001846.3801= 336-1-derekjohn.clark@gmail.com?part=3D4