From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C482A3054E4 for ; Fri, 9 Oct 2026 19:18:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.67.36.66 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791573502; cv=none; b=Q235foaS6VMy2IZrva0lIALb5CemZrzcQ23W0vb9syIcqLUUuJuhCByp0LTG0RDayDtWhiGKAFQs12fj5oWAruLhTf3OlKpDrKZSVbyEpKX6xAWCopzWyIlzJm1KBSP+kC/tKAVo+Ujfsi3JpFTEZ7wGYNCDm3t2wMqbEorGYgE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791573502; c=relaxed/simple; bh=QJNnLTWbPIc0IRk3LBCKNNqgIK8CqMpv7T7NZvSxuks=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=q6CPZkLYSi4QQPv4DlxHwLjj0xCsXK8mo6Hkfxh2/7CKVEk65wTeGpASljTaOFqE83PokPjXaRrc7U0A+shKSWNDhEviooBxZkHJ3ujYUi/ll5v9p3BivPXKbaluUH/BK61ZRVQxmE1JhB2Wy6lmMK7lOPDEoWVocXdypVy6aAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.de; spf=pass smtp.mailfrom=posteo.de; dkim=pass (2048-bit key) header.d=posteo.de header.i=@posteo.de header.b=nm7Ex7gY; arc=none smtp.client-ip=185.67.36.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=posteo.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.de header.i=@posteo.de header.b="nm7Ex7gY" Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id F28DD240104 for ; Fri, 9 Oct 2026 21:18:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posteo.de; s=1984.8680eb; t=1791573497; bh=FNjC8CQdezjbjbIN10GIqhnKvMIJQ0qM8m+UWFEtdXg=; h=Message-ID:Subject:From:To:Cc:Date:Autocrypt:Content-Type: MIME-Version:OpenPGP:From; b=nm7Ex7gYZOsJ42vAFuqWTGKoOBuqVmc0zIQ4TygFWzCP6QGveqzs17CKAKbcOauIk FVc2wJryW1hgPoki8WkDtxJ6ZxthDdZyZd3cghvObzGxvT13WYfVQOkvHnKfa8H4uW bb06VdVNTnFTL7onBTF2WIF/GH4OFhmgBE4yIlM6lPmCdDNMv7jULuaCWnBQ3L4j5d MHs56Sm4aVkN3pbqzRA7gYDDgMvPuPClm6ihbYM2oC19JxDjmh6AY2Dl+lypVL0R+n 2bMRMefAer1Uj0O2o5SeVTwa5I1aZoK5glsBUw6e9Q61kw2OsAzFpIOOYmTym1vlgo n4V2lvdvIozlw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4j1c8Q0hVrz9rxD; Fri, 9 Oct 2026 21:18:13 +0200 (CEST) Message-ID: <81e1aa92ebc389468eb6f493393a1c58a79373e7.camel@posteo.de> Subject: Re: [PATCH v26 3/4] rust: leds: Add multicolor classdev abstractions From: Markus Probst To: Boqun Feng Cc: Lee Jones , Pavel Machek , Greg Kroah-Hartman , Dave Ertman , Leon Romanovsky , Miguel Ojeda , Alex Gaynor , Gary Guo , =?ISO-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , "Rafael J. Wysocki" , Bjorn Helgaas , Krzysztof =?ISO-8859-1?Q?Wilczy=B4nski?= , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , Onur =?ISO-8859-1?Q?=D6zkan?= , Ira Weiny , rust-for-linux@vger.kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Date: Fri, 09 Oct 2026 19:18:16 +0000 In-Reply-To: References: <20260930-rust_leds-v26-0-83837331020e@posteo.de> <20260930-rust_leds-v26-3-83837331020e@posteo.de> Autocrypt: addr=markus.probst@posteo.de; prefer-encrypt=mutual; keydata=mQINBGiDvXgBEADAXUceKafpl46S35UmDh2wRvvx+UfZbcTjeQOlSwKP7YVJ4JOZrVs93 qReNLkOWguIqPBxR9blQ4nyYrqSCV+MMw/3ifyXIm6Pw2YRUDg+WTEOjTixRCoWDgUj1nOsvJ9tVA m76Ww+/pAnepVRafMID0rqEfD9oGv1YrfpeFJhyE2zUw3SyyNLIKWD6QeLRhKQRbSnsXhGLFBXCqt 9k5JARhgQof9zvztcCVlT5KVvuyfC4H+HzeGmu9201BVyihJwKdcKPq+n/aY5FUVxNTgtI9f8wIbm fAjaoT1pjXSp+dszakA98fhONM98pOq723o/1ZGMZukyXFfsDGtA3BB79HoopHKujLGWAGskzClwT jRQxBqxh/U/lL1pc+0xPWikTNCmtziCOvv0KA0arDOMQlyFvImzX6oGVgE4ksKQYbMZ3Ikw6L1Rv1 J+FvN0aNwOKgL2ztBRYscUGcQvA0Zo1fGCAn/BLEJvQYShWKeKqjyncVGoXFsz2AcuFKe1pwETSsN 6OZncjy32e4ktgs07cWBfx0v62b8md36jau+B6RVnnodaA8++oXl3FRwiEW8XfXWIjy4umIv93tb8 8ekYsfOfWkTSewZYXGoqe4RtK80ulMHb/dh2FZQIFyRdN4HOmB4FYO5sEYFr9YjHLmDkrUgNodJCX CeMe4BO4iaxUQARAQABtCdNYXJrdXMgUHJvYnN0IDxtYXJrdXMucHJvYnN0QHBvc3Rlby5kZT6JAl QEEwEIAD4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AWIQSCdBjE9K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jRIVlRM+eFbUl8XwxwVrAkojF5IraH2qRvg VCmuFsHUW07FUlrDrzpjXsD73cKppoFGDCdDR0BHJepXbFLS9+AqkT+guRJlnCTg2p+TQtnbwPgKp Vj98JixovCl99zRYTsL2bRNU5+q8iET65VMJ1ydyNanvLd5vI/NqDkXhlXLsGmdaDTtu4R21PkToX dQNGrZ91M9nlIBKw8Y7c7xZ4098qX2b8JX/CxD+gC1r4C8vuA3GkhFLx+KlkON7LyiJPkrePp6Qky jfGillcaQOqFZ3WwVqyzG1BUfTow== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-y8/PBsqchvqDf6iK4n7Q" Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 OpenPGP: url=https://posteo.de/keys/markus.probst@posteo.de.asc; preference=encrypt --=-y8/PBsqchvqDf6iK4n7Q Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2026-10-09 at 11:52 -0700, Boqun Feng wrote: > On Wed, Sep 30, 2026 at 01:05:32PM +0000, Markus Probst wrote: > > Implement the abstractions needed for multicolor led class devices, > > including: > >=20 > > * `led::MultiColor` - the led mode implementation > >=20 > > * `MultiColorSubLed` - a safe wrapper arround `mc_subled` > >=20 > > * `led::MultiColorDevice` - a safe wrapper around `led_classdev_mc` > >=20 > > * `led::DeviceBuilder::build_multicolor` - a function to register a new > > multicolor led class device > >=20 > > Signed-off-by: Markus Probst > > --- > > rust/bindings/bindings_helper.h | 1 + > > rust/kernel/led.rs | 34 ++- > > rust/kernel/led/multicolor.rs | 445 ++++++++++++++++++++++++++++++++= ++++++++ > > 3 files changed, 479 insertions(+), 1 deletion(-) > >=20 > > diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_h= elper.h > > index 4b31aa7f432f..81a03985322a 100644 > > --- a/rust/bindings/bindings_helper.h > > +++ b/rust/bindings/bindings_helper.h > > @@ -69,6 +69,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > diff --git a/rust/kernel/led.rs b/rust/kernel/led.rs > > index c17f8ef75006..4b66fe41a80c 100644 > > --- a/rust/kernel/led.rs > > +++ b/rust/kernel/led.rs > > @@ -30,8 +30,16 @@ > > types::Opaque, // > > }; > > =20 > > +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR)] > > +mod multicolor; > > mod normal; > > =20 > > +#[cfg(CONFIG_LEDS_CLASS_MULTICOLOR)] > > +pub use multicolor::{ > > + MultiColor, > > + MultiColorDevice, > > + MultiColorSubLed, // > > +}; > > pub use normal::{ > > Device, > > Normal, // > > @@ -233,7 +241,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 supp= ort." > > + )] > > + #[cfg_attr( > > + not(CONFIG_LEDS_CLASS_MULTICOLOR), > > + doc =3D "Use this color for a `MultiColor` led with rgb suppor= t." > > + )] > > Rgb =3D bindings::LED_COLOR_ID_RGB, > > Purple =3D bindings::LED_COLOR_ID_PURPLE, > > Orange =3D bindings::LED_COLOR_ID_ORANGE, > > @@ -274,7 +299,14 @@ fn try_from(value: u32) -> core::result::Result { > > /// > > /// Each led mode has its own led class device type with different cap= abilities. > > /// > > -/// 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; > > diff --git a/rust/kernel/led/multicolor.rs b/rust/kernel/led/multicolor= .rs > > new file mode 100644 > > index 000000000000..309487bdf38a > > --- /dev/null > > +++ b/rust/kernel/led/multicolor.rs > > @@ -0,0 +1,445 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > + > > +//! Led mode for the `struct led_classdev_mc`. > > +//! > > +//! C header: [`include/linux/led-class-multicolor.h`](srctree/include= /linux/led-class-multicolor.h) > > + > > +use core::{ > > + cell::UnsafeCell, > > + num::NonZero, > > + ptr, // > > +}; > > + > > +use crate::types::ScopeGuard; > > + > > +use super::*; > > + > > +/// The led mode for the `struct led_classdev_mc`. Leds with this mode= can have multiple colors. > > +pub enum MultiColor {} > > +impl Mode for MultiColor { > > + type Device<'bound, T: LedOps + 'bound> =3D MultiCo= lorDevice<'bound, T>; > > +} > > +impl private::Sealed for MultiColor {} > > + > > +/// The multicolor sub led info representation. > > +/// > > +/// This structure represents the Rust abstraction for a C `struct mc_= subled`. > > +#[repr(C)] > > +#[derive(Debug)] > > +#[non_exhaustive] > > +pub struct MultiColorSubLed { > > + /// The color of the sub led > > + pub color: Color, > > + brightness: UnsafeCell, > > + intensity: UnsafeCell, >=20 > These should be `Atomic`, or am I missing something here? Using > `Atomic` should resolve sashiko's comment on this patch. Snippet of the `Atomic::from_ptr` rustdoc: " For the duration of 'a, other accesses to *ptr must not cause data races (defined by LKMM) against atomic operations on the returned reference. Note that if all other accesses are atomic, then this safety requirement is trivially fulfilled. " This safety requirement is likely not met if I see this correctly, because the led subsystem does not use atomic accesses. Ofc, this function won't be used, but I think given that the same struct is also accessed by the C-side, it should also apply here. Like Sashiko suggests, "core::ptr::read_volatile()" might be a better option to prevent certain compiler optimizations. Thanks - Markus Probst >=20 > Regards, > Boqun >=20 > > + /// The maximum supported intensity value. > > + /// > > + /// If None the maximum intensity equals to [`LedOps::MAX_BRIGHTNE= SS`]. > > + pub max_intensity: Option>, > > + /// Arbitrary data for the driver to store. > > + pub channel: u32, > > +} > > + > [...] --=-y8/PBsqchvqDf6iK4n7Q Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQJPBAABCAA5FiEEgnQYxPSsWOdyMMRzNHYf+OetQ9IFAmrJPe8bFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMiwyAAoJEDR2H/jnrUPS4aUP/R/DLeYIdqUXlPuo2jqy kuQ7hx8WN9Y1iTNTOAn/GE8vuViEUL1fsEsNG3Uz1JzPQ5kCeWpyX1JXs229Bygt yWmwE+AAg35U/pAzAfOzFcFScgRuczxfMH3DynPqSoh3AhKg1XHHJJFnBk8KytO0 GWIsw7ygpwxDAMqirniroLCpFmjyIccZ/dKKunVlFXLw9M3JAOyXIK++JTnNtWtH ai88NG3GoX6AQoO30hmntuV88bTmPkupGAnOtOeaDNPiFiqdqmG4GcKAoCepiwsu /DMYos3IYBJuiFx1tg+ou/3FiCp4yoHMoXKjHW588GR3HBlescX3EpQACDyxi2HS sQWA8sEp2I5FfZO0oes4WbdOqCW9e1p24I8a5Rnc0BmoX9z4+RUlgpOK/xqRupTY JYBc46VWOakXHXpMgrS0Um6m8oDSsR9DmfqYuIpUAgM5Ex/bUUFWooeXqAPLAGWg mBVrYSJpSsRz2ojkPSOKmv26/UZPDEDl67Cyccc2ioOCOlq7LwCjYZn9BT7aqJRg 6t+WLiSvA7OjAhGJyPgb1iFBTtWOAKxnJ9T5ydFDkEiH3LLaqXvredIm4WuoI8AY 7WuEpfR2P4QOxKzOQCVeItEYzDwX8CnLiCCQ1WFe0ygs6RBPY3wghAWZXAXLIFva Y9kc1CNmAR+Rj1eFm+r51kOt =CPoW -----END PGP SIGNATURE----- --=-y8/PBsqchvqDf6iK4n7Q--