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=1796335243; b=bkKCw0Cqf1zC3Ibv7ZER1uVNNqXdKoJvCUgu68Z3pRkQuh4yDPSUIXJ9n2tqS7WVV27F 8YAjaGkoE/AXc6/MLmI+uhJSQF3AmRJ6fGCHo89SQcKWlFm92nYMT6ZjPtFKktsBD58pE gTylEVgPJ+j+qkSS3HkxibyTw/Hx4PWFpY+1BoE8el5HN6tY7rWhO4QPaS2+d+es/hfxz 0r6Zqlj+6/4W2YQGRNnpITIqFjq0z3vDQ6rr7wYAiwzjvHvNxyMWw6LGALWAieuf3kB0l o/KQ+wL9Yesod9+eHtETymPfP/rSy/7Akf/QQsK9d8VHc+XtCkZrMjAXWY87pvL7M/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796335243; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=aSblONgGc/bfg12xdNOCWAHWhh4IuW7l5hyvfsj8ZDc=; b=hommPmWZNGxxL6uzSr4k7dvDIH6wqeh9ZEGhluXOnvFrS+2cBi+m6Hr/1czBq8ekaoZj mz9HtqREe1oA2sg0Lr7eIXbiDdYTF1fVActTB8QtNA8im2vOvrE+wp19fqNQmMih4drYQ udA5W4s/fLdHhBdFX8H5EcJniuSQXQ/bNJ3Xk/v83wwhvSeQ/xA1xq58cH/QMUdIMFME5 prwYWsv1iC7cLxEAsU/VkKCv2f1OA7A1P8HcxVseWyWk87N3Xdeq/TrdpcdgPXMC1XvyJ XKlJERFv0OCfH6jyGjghG0822IiQmw/yn+B1tcgmyeWAoUSfreQJJlO+Krsp9vKv1bg== 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=HDBv4qSJ; 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 0745D606A689; Thu, 3 Dec 2026 22:00: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=HDBv4qSJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A561F00A24; Thu, 3 Dec 2026 22:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796335242; bh=aSblONgGc/bfg12xdNOCWAHWhh4IuW7l5hyvfsj8ZDc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HDBv4qSJTB4ZqYjqcEsQpllvW3zcIES3WfejAklNLcqrh0nflBORECzQqZgQVyTXD VR+E/lp2DE/qEa1kBqA50aGL4SuZSo/ONSkpj5pgM58kEZbcCaE6wYe3fiI43HPif6 3Mj2WnHcujzUzIc9zuaahjrH4N1+2U7n6rOOJ0eFKTXjb4xooQ6+Rnu6o9ebcHcwh9 A4gj5TVUv5IWeVJ03FsepFtP6lDSprhFjNkzl0bop3EBp5NOdtPmEQgjI350mu+0Zt D1Eyrs7vikn5t8S4oued4nfCB9e6vTs+NQQLW/ajvDmWRg9xkS1PdlkEFQrcbBZh5S 7Z1UKZStjCYfg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v29 3/4] rust: leds: Add multicolor classdev abstractions Reply-To: sashiko-reviews@lists.linux.dev To: "Markus Probst" Cc: linux-leds@vger.kernel.org, linux-pci@vger.kernel.org, lee@kernel.org, ojeda@kernel.org, gary@garyguo.net In-Reply-To: <20261203-rust_leds-v29-3-dc8a8ccb96d7@posteo.de> References: <20261203-rust_leds-v29-0-dc8a8ccb96d7@posteo.de> <20261203-rust_leds-v29-3-dc8a8ccb96d7@posteo.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 22:00:42 +0000 X-Mailing-List: linux-leds@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] rust: leds: unsynchronized led_mc_calc_color_components() in callbacks - [Low] rust: leds: broken rustdoc links when LEDS_CLASS_MULTICOLOR=3Dm - [Low] rust: leds: missing INVARIANT comments and #[inline] in multicolor.rs -- commit 1e49a309518af64831c1082f7d1d80c038a985c7 Author: Markus Probst rust: leds: Add multicolor classdev abstractions This commit adds Rust abstractions for multicolor LED class devices (struct led_classdev_mc and struct mc_subled), including the MultiColor mode, MultiColorDevice, MultiColorSubLed, MultiColorSubLedBuilder, and DeviceBuilder::build_multicolor(). > diff --git a/rust/kernel/led.rs b/rust/kernel/led.rs > index f0c64821334ba..56ffc5bc4933a 100644 > --- a/rust/kernel/led.rs > +++ b/rust/kernel/led.rs > @@ -32,8 +32,17 @@ > types::Opaque, // > }; > =20 > +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR =3D "y")] > +mod multicolor; > mod normal; > =20 > +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR =3D "y")] > +pub use multicolor::{ > + MultiColor, > + MultiColorDevice, > + MultiColorSubLed, > + MultiColorSubLedBuilder, // > +}; > pub use normal::{ > Device, > Normal, // > @@ -235,7 +244,24 @@ pub enum Color { > Violet =3D bindings::LED_COLOR_ID_VIOLET, > Yellow =3D bindings::LED_COLOR_ID_YELLOW, > Ir =3D bindings::LED_COLOR_ID_IR, > + #[cfg_attr( > + CONFIG_LEDS_CLASS_MULTICOLOR, > + doc =3D "Use this color for a [`MultiColor`] led." > + )] > + #[cfg_attr( > + not(CONFIG_LEDS_CLASS_MULTICOLOR), > + doc =3D "Use this color for a `MultiColor` led." > + )] > + /// If the led supports RGB, use [`Color::Rgb`] instead. > Multi =3D bindings::LED_COLOR_ID_MULTI, > + #[cfg_attr( > + CONFIG_LEDS_CLASS_MULTICOLOR, > + doc =3D "Use this color for a [`MultiColor`] led with rgb suppor= t." > + )] > + #[cfg_attr( > + not(CONFIG_LEDS_CLASS_MULTICOLOR), > + doc =3D "Use this color for a `MultiColor` led with rgb support." > + )] > Rgb =3D bindings::LED_COLOR_ID_RGB, > Purple =3D bindings::LED_COLOR_ID_PURPLE, > Orange =3D bindings::LED_COLOR_ID_ORANGE, > @@ -268,7 +294,14 @@ fn try_from(value: u32) -> core::result::Result { > /// > /// Each led mode has its own led class device type with different capab= ilities. > /// > -/// See [`Normal`]. > +#[cfg_attr( > + CONFIG_LEDS_CLASS_MULTICOLOR, > + doc =3D "See [`Normal`] and [`MultiColor`]." > +)] > +#[cfg_attr( > + not(CONFIG_LEDS_CLASS_MULTICOLOR), > + doc =3D "See [`Normal`] and `MultiColor`." > +)] > pub trait Mode: private::Sealed { > /// The class device for the led mode. > type Device<'bound, T: LedOps + 'bound>: Deref; [Severity: Low] Will these cfg_attr doc attributes break make rustdoc when CONFIG_LEDS_CLASS=3Dy and CONFIG_LEDS_CLASS_MULTICOLOR=3Dm? LEDS_CLASS_MULTICOLOR is tristate, and conf_write_rustccfg() emits the bare CONFIG_LEDS_CLASS_MULTICOLOR cfg for both y and m. When it is set to m, mod multicolor and MultiColor are not compiled because they are gated on CONFIG_LEDS_CLASS_MULTICOLOR =3D "y", so the intra-doc links to MultiColor = on Color::Multi, Color::Rgb, and Mode become unresolved and fail rustdoc under -Dwarnings. Checking CONFIG_LEDS_CLASS_MULTICOLOR =3D "y" in these cfg_attr conditions would match the module gate. > diff --git a/rust/kernel/led/multicolor.rs b/rust/kernel/led/multicolor.rs > new file mode 100644 > index 0000000000000..492a132579d6c > --- /dev/null > +++ b/rust/kernel/led/multicolor.rs [ ... ] > + /// Build the sub led descriptor. > + #[inline] > + pub const fn build(self) -> MultiColorSubLed { > + MultiColorSubLed(Opaque::new(bindings::mc_subled { > + brightness: 0, > + channel: self.channel, > + color_index: self.color as u32, > + intensity: self.initial_intensity, > + max_intensity: if let Some(max_intensity) =3D self.max_inten= sity { > + max_intensity.get() > + } else { > + 0 > + }, > + })) > + } [ ... ] > +impl Clone for MultiColorSubLed { > + fn clone(&self) -> Self { > + Self(Opaque::new(bindings::mc_subled { > + color_index: self.color() as u32, > + brightness: self.brightness(), > + intensity: self.intensity(), > + max_intensity: self.max_intensity().map(NonZero::get).unwrap= _or_default(), > + channel: self.channel(), > + })) > + } > +} [ ... ] > +impl<'bound, T: LedOps + 'bound> Deref for MultiColorDevice<'bound, T> { > + type Target =3D T; > + > + fn deref(&self) -> &Self::Target { > + &self.ops > + } > +} > + > +// SAFETY: A `led::MultiColorDevice` can be unregistered from any thread. > +unsafe impl<'bound, T: 'bound + Send> Send for MultiColorDevice<'bound, = T> {} > + > +// SAFETY: `led::MultiColorDevice` can be shared among threads because a= ll methods of `led::Device` > +// are thread safe. > +unsafe impl<'bound, T: 'bound + Sync> Sync for MultiColorDevice<'bound, = T> {} [Severity: Low] MultiColorSubLed documents an Invariants section, so MultiColorSubLedBuilder::build() and MultiColorSubLed::clone() should carry INVARIANT comments explaining why the invariants hold. In addition, MultiColorSubLed::clone() and MultiColorDevice::deref() are small kernel-crate methods missing #[inline], and the Sync safety comment on MultiColorDevice refers to led::Device instead of led::MultiColorDevice. [ ... ] > + unsafe extern "C" fn brightness_set_callback( > + led_cdev: *mut bindings::led_classdev, > + brightness: u32, > + ) { > + // SAFETY: The function's contract guarantees that `led_cdev` is= a valid pointer to a > + // `led_classdev` embedded within a `led::MultiColorDevice`. > + let classdev =3D unsafe { MultiColorDevice::::from_raw(led_cd= ev) }; > + > + // SAFETY: `classdev.classdev.get()` is guaranteed to be a point= er to a valid > + // `led_classdev_mc`. > + unsafe { bindings::led_mc_calc_color_components(classdev.classde= v.get(), brightness) }; > + > + let _ =3D classdev.brightness_set(brightness); > + } > + > + /// # Safety > + /// `led_cdev` must be a valid pointer to a `led_classdev` embedded = within a > + /// `led::MultiColorDevice`. > + /// This function is called on setting the brightness of a led immed= iately. > + unsafe extern "C" fn brightness_set_blocking_callback( > + led_cdev: *mut bindings::led_classdev, > + brightness: u32, > + ) -> i32 { > + from_result(|| { > + // SAFETY: The function's contract guarantees that `led_cdev= ` is a valid pointer to a > + // `led_classdev` embedded within a `led::MultiColorDevice`. > + let classdev =3D unsafe { MultiColorDevice::::from_raw(le= d_cdev) }; > + > + // SAFETY: `classdev.classdev.get()` is guaranteed to be a p= ointer to a valid > + // `led_classdev_mc`. > + unsafe { bindings::led_mc_calc_color_components(classdev.cla= ssdev.get(), brightness) }; > + > + classdev.brightness_set(brightness)?; > + Ok(0) > + }) > + } [Severity: Medium] Can calling led_mc_calc_color_components() here race with concurrent brightness updates? led_mc_calc_color_components() updates subled_info[i].brightness in-place with plain non-atomic stores and no lock. The LED core does not serialize brightness callbacks under one lock: for non-blocking LEDs, led_timer_function() in softirq context can run concurrently with sysfs brightness_store(), and for blocking LEDs, led_set_brightness_sync() can race with set_brightness_delayed() on leds_wq: CPU0 CPU1 brightness_store() brightness_set_callback(255) led_timer_function() led_mc_calc_color_components() brightness_set_callback(0) classdev.brightness_set(255) led_mc_calc_color_components() subleds()[0].brightness() subled_info[i].brightness =3D 0 subleds()[1].brightness() <-- data race / torn channel values Because Adapter calls led_mc_calc_color_components() before entering LedOps::brightness_set(), a driver cannot hold its own lock across the calculation and hardware update, resulting in a data race and torn per-channel brightness values programmed into the LED hardware. Exposing a method on MultiColorDevice so drivers call led_mc_calc_color_components() under their own lock would avoid the race, let devices with hardware global brightness skip it, and allow blink_set() to compute channel brightness when needed. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-rust_leds-= v29-0-dc8a8ccb96d7@posteo.de?part=3D3