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=1796344791; b=WJjHEUQ3eFr5aRujELLb48eSgyohN7gwut/ESlKFpnOt7tZUi691Lb5T/alHLF/8gpLN QokWDFvwrFzNXugGrlcPd+eH+DaFh0P6aPWaPrrFylYiHANul0FNOK9Ir9kUSv3GtrHtX mQYk818PAN8Gu5HWEI3EhcG5YqMR4DAEIYGyg3TcXxJxZSEFgcjTTE2/HrM5f0Gat69K6 Nzo/W5QcPNvIwHZbO49048hva0QyQS11OeWg21Lsz5OcHGWXS4srAwEKIsOg5qvH7Aiwr I+UdwwHxLZ4zDjwnwDCKAUCrRfTt1e86wgpZBlMQtHDijfmsha8GKQqIsTOFkS8yonw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344791; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=lOVeH3LCvaqEr1SHGJvOoKf+aTChbUjsHzlpXWfzgjU=; b=zc6LpoPZUuWsITBKk1ZWWZdn50wCBE5eU7JcS1OUMeteao4GkJmWz0XBo6IhoZFZZS/0 H+p3aAR6cwwA/mmcnltQYtRsBctOT1eYtMmiyDQ5PsR8SanOOyuoyC0gDj06Xev7LndIC YiOodsUqBXsjA//7xQYi2dwNGeBj6gULj0d6SW7umbBSf44kikah5OUqRK9L+rKbK/uDZ ab7N5wNHuWgJnvJNN98zv4A54aVRDCBmhr/XXJlkV9WQPulYCEtRa5owH1Y+kYeVOFmcf vlTlBdOgesFCmgGAJKWVL3LCB0p5hvyh+4+tzviSfU8DKo3GXY4avLGGjDXuz9jw8fQ== 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=Uu1MEvyz; 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 30FF6606A322; Fri, 4 Dec 2026 00:39:51 +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=Uu1MEvyz Received: by smtp.kernel.org (Postfix) with ESMTPSA id C160D1F000CE; Fri, 4 Dec 2026 00:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796344791; bh=lOVeH3LCvaqEr1SHGJvOoKf+aTChbUjsHzlpXWfzgjU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Uu1MEvyzMN6liEgkt+vRLCvHZKOCFVIMuxz0o993DYa0WxRabmd3f3yoi5nsmKT16 4TJtBm8OZa18PA2oE2Nrni9PL6n/YObEyBCegImwdBozXwOdIV72x+03CXg9g/jXJQ MJL5ORXtL9DOq0Vkr2OY9jd+8PijwntBqJAagpI8BzmBgnLrSp6LEvCeQgyTDHY9NB O2YDDOpOljNZofVKou4x3dA1/TB7U04vlOwxAz4iGLv2G4cx03iRjONXjy7oIz8jdj I2fF8DCJSJ1x7lP1fC593i4Zhxl9O4S3zubymq9eW3CDR9ieccyG6iIxUTVrzE+p5v J5KOi1FdNVhAA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 7/8] HID: hid-msi: Switch the RGB LED to brightness_set_blocking 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-8-derekjohn.clark@gmail.com> References: <20261204001846.3801336-1-derekjohn.clark@gmail.com> <20261204001846.3801336-8-derekjohn.clark@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 00:39:50 +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 7 potential issues to consider: - [Medium] HID: hid-msi: non-blocking callback registered as brightness_set_blocking - [Medium] HID: hid-msi: apply_store() races with set_brightness_work before SYNC_TO_ROM - [Medium] HID: hid-msi: claw_write_rgb_state() clobbers concurrent rgb_dirty updates - [Medium] HID: hid-msi: brightness_set_blocking exposes lost brightness update race - [Medium] HID: hid-msi: claw_led_brightness_set_blocking() races on led_cdev->brightness - [Medium] HID: hid-msi: unflushed brightness work breaks suspend drain and rgb_dirty - [Low] HID: hid-msi: commit message omits new led_cdev->brightness assignment -- commit 16672f0371737d043ea0a0ea456c2660ded1fb00 Author: Derek J. Clark > HID: hid-msi: Switch the RGB LED to brightness_set_blocking > > brightness_set must not sleep, so led-core may call it from the blink > timer or a trigger's hardirq. The work this handler queues is an HID > transaction, so register brightness_set_blocking instead, like > hid-playstation does for the DualSense lightbar. > > No path that led-core uses to reach this handler sleeps, so this is an > interface correction rather than a bug fix. > > Signed-off-by: Derek J. Clark [Severity: Low] Should the commit message also describe the new frame_lock-protected assignment and clamping of led_cdev->brightness in claw_led_brightness_set_blocking()? The previous claw_led_brightness_set() ignored its brightness parameter, so mutating led_cdev->brightness is a behavioral change beyond switching the callback interface. > diff --git a/drivers/hid/hid-msi.c b/drivers/hid/hid-msi.c > index d2cd0d7397aa4..f4b592c7d2977 100644 > --- a/drivers/hid/hid-msi.c > +++ b/drivers/hid/hid-msi.c > @@ -1716,8 +1716,8 @@ static ssize_t speed_range_show(struct device *dev, > } > static DEVICE_ATTR_RO(speed_range); > =20 > -static void claw_led_brightness_set(struct led_classdev *led_cdev, > - enum led_brightness _brightness) > +static int claw_led_brightness_set_blocking(struct led_classdev *led_cde= v, > + enum led_brightness brightness) > { > struct led_classdev_mc *led_mc =3D container_of(led_cdev, struct led_cl= assdev_mc, led_cdev); > struct claw_drvdata *drvdata =3D container_of(led_mc, struct claw_drvda= ta, led_mc); > @@ -1725,10 +1725,16 @@ static void claw_led_brightness_set(struct led_cl= assdev *led_cdev, > 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->rgb_registered)) > - return; > + return 0; > } > =20 > + scoped_guard(spinlock_irqsave, &drvdata->frame_lock) > + led_cdev->brightness =3D min_t(unsigned int, brightness, > + led_cdev->max_brightness); [Severity: Medium] Does writing led_cdev->brightness here introduce a data race with led-core? claw_led_brightness_set_blocking() runs asynchronously on leds_wq without led_cdev->led_access and only holds drvdata->frame_lock, whereas led-core reads and writes led_cdev->brightness without frame_lock in led_set_brightness_nosleep(), multi_intensity_store(), brightness_show(), and led_timer_function(). CPU0 (leds_wq) CPU1 (sysfs) set_brightness_delayed() clear LED_SET_BRIGHTNESS claw_led_brightness_set_blocking(10) brightness_store(80) led_cdev->brightness =3D 80 delayed_set_value =3D 80 set LED_SET_BRIGHTNESS led_cdev->brightness =3D 10 <-- overwrites newer value multi_intensity_store() led_set_brightness(10) delayed_set_value =3D 10 When multi_intensity_store() reads the clobbered value while LED_SET_BRIGHTNESS is set, it overwrites delayed_set_value and permanently drops the newer brightness; the same race with led_timer_function() can corrupt software blink phase and blink_brightness. Storing a separate frame_lock-protected brightness field in struct claw_drvdata for claw_write_rgb_state() would avoid mutating led_cdev->brightness. > claw_rgb_schedule(drvdata); > + > + return 0; > } [Severity: Medium] Can claw_write_rgb_state() clobber drvdata->rgb_dirty when claw_rgb_schedule() runs concurrently? claw_write_rgb_state() snapshots the RGB state, runs sleeping claw_hw_output_report() transfers, and then unconditionally clears drvdata->rgb_dirty without serializing against claw_rgb_schedule(): CPU0 (rgb_queue) CPU1 (sysfs / suspend) claw_write_rgb_state() snapshot RGB state claw_hw_output_report() ... claw_rgb_schedule() rgb_dirty =3D true mod_delayed_work(rgb_queue, 50ms) rgb_dirty =3D false <-- clobbers pending dirty flag claw_suspend() cancel_delayed_work_sync(rgb_queue) If the system suspends before the 50 ms delayed work fires, claw_suspend() cancels rgb_queue while rgb_dirty is false, so cfg_resume_fn() skips replaying the newer RGB update on resume. [ ... ] > @@ -1946,7 +1952,7 @@ static int claw_probe(struct hid_device *hdev, u8 e= p) > drvdata->led_mc.led_cdev.brightness =3D 0x50; > drvdata->led_mc.led_cdev.max_brightness =3D 0x64; > drvdata->led_mc.led_cdev.color =3D LED_COLOR_ID_RGB; > - drvdata->led_mc.led_cdev.brightness_set =3D claw_led_brightness_set; > + drvdata->led_mc.led_cdev.brightness_set_blocking =3D claw_led_brightnes= s_set_blocking; [Severity: Medium] Should this stay on brightness_set instead of switching to brightness_set_blocking? claw_led_brightness_set_blocking() does not sleep or perform HID I/O; it only takes irqsave spinlocks and calls mod_delayed_work(), which is safe in atomic context. Per include/linux/leds.h, brightness_set_blocking is for callbacks that synchronously update hardware, so registering a work scheduler there makes led_set_brightness_sync() return 0 before the 50 ms delayed HID write runs and forces every led_set_brightness_nopm() call through the single-threaded global ordered leds_wq just to queue drvdata->rgb_queue. [Severity: Medium] Can apply_store() now commit stale RGB state to ROM before a pending brightness or multi_intensity write is scheduled? With brightness_set cleared, brightness_store() and multi_intensity_store() queue led_cdev->set_brightness_work on leds_wq and return before claw_rgb_schedule() runs, while apply_store() only flushes drvdata->rgb_queue: CPU0 (userspace) CPU1 (leds_wq) brightness_store() queue_work(set_brightness_work) apply_store() flush_delayed_work(rgb_queue) <-- nothing queued yet SYNC_TO_ROM <-- commits stale MCU state set_brightness_delayed() claw_rgb_schedule() If set_brightness_work has not run yet when userspace writes to apply, CLAW_COMMAND_TYPE_SYNC_TO_ROM persists the old RGB state to flash and the new setting is lost across a reset. [Severity: Medium] Does switching to brightness_set_blocking expose multi_intensity_store() to dropping a pending brightness update? When a second non-zero brightness_store() arrives while LED_SET_BRIGHTNESS is still pending, led_set_brightness() updates led_cdev->delayed_set_value and returns early without updating led_cdev->brightness. If multi_intensity_store() then runs before set_brightness_work executes, it passes the stale led_cdev->brightness back into led_set_brightness(), overwriting delayed_set_value and silently discarding the newer brightness. [Severity: Medium] Does deferring claw_rgb_schedule() onto leds_wq break the suspend drain in claw_suspend() and the rgb_dirty protection across reset-resume? leds_wq is a global ordered workqueue without WQ_FREEZABLE, and claw_suspend() cancels cfg_resume, cfg_setup, and rgb_queue without draining led_cdev->set_brightness_work: CPU0 (sysfs / PM) CPU1 (leds_wq) multi_intensity_store() update subled_info[].intensity queue_work(set_brightness_work) claw_suspend() cancel_delayed_work_sync(rgb_queue) msi_reset_resume() cfg_setup_fn() rgb_dirty =3D=3D false claw_read_rgb_config() <-- overwrites subled_info with stale color set_brightness_delayed() claw_rgb_schedule() <-- uses stale col= or Because multi_intensity_store() updates subled_info[].intensity in place and returns before rgb_dirty is set, set_brightness_work can re-arm rgb_queue during suspend or remain pending until cfg_setup_fn() runs on reset-resume (the default path with commit "USB: core: quirks: Add RESET_RESUME quirk for MSI Claw"), where claw_profile_event() overwrites subled_info with the stale MCU color and permanently loses the user's color update. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204001846.3801= 336-1-derekjohn.clark@gmail.com?part=3D7