From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: lee@kernel.org, linux-pci@vger.kernel.org, ojeda@kernel.org,
linux-leds@vger.kernel.org
Subject: Re: [PATCH RESEND v23 3/3] rust: leds: add multicolor classdev abstractions
Date: Wed, 19 Aug 2026 19:10:32 +0000 [thread overview]
Message-ID: <20260819191032.DF95B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819-rust_leds-v23-3-2716a4ef89a4@posteo.de>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Incorrect manual reference count management for `fwnode` causes memory leaks and potential Use-After-Free (UAF).
- [High] Plain, unsynchronized reads of `intensity` and `brightness` from `UnsafeCell` cause data races and Undefined Behavior.
- [Low] The commit message violates formatting conventions (capitalization) and contains a typo.
--
--- Patch [3]: [PATCH RESEND v23 3/3] rust: leds: add multicolor classdev abstractions ---
commit 2486b1ac4294e9421b47197f76e5b346cbfb370a
Author: Markus Probst <markus.probst@posteo.de>
rust: leds: add multicolor classdev abstractions
This patch implements the abstractions needed for multicolor led class devices.
It introduces the MultiColor mode, MultiColorSubLed wrapper, MultiColorDevice
wrapper, and device builder functions.
> rust: leds: add multicolor classdev abstractions
[Severity: Low]
This isn't a bug, but the commit message subject violates the subsystem
capitalization convention. Could this be capitalized as "Add multicolor..."?
> * `MultiColorSubLed` - a safe wrapper arround `mc_subled`
[Severity: Low]
This isn't a bug, but there is a typo (arround) in the commit message.
> diff --git a/rust/kernel/led/multicolor.rs b/rust/kernel/led/multicolor.rs
> new file mode 100644
> --- /dev/null
> +++ b/rust/kernel/led/multicolor.rs
[ ... ]
> + pub const fn intensity(&self) -> u32 {
> + // SAFETY:
> + // - `self.intensity.get()` is a valid pointer to `u32`.
> + // - We don't have exclusive or immutable access to `self.intensity`,
> + // but the alignment should prevent "load tearing".
> + unsafe { *self.intensity.get() }
> + }
> +
> + /// The brightness of the sub led.
> + #[inline]
> + pub const fn brightness(&self) -> u32 {
> + // SAFETY:
> + // - `self.brightness.get()` is a valid pointer to `u32`.
> + // - We don't have exclusive or immutable access to `self.brightness`,
> + // but the alignment should prevent "load tearing".
> + unsafe { *self.brightness.get() }
> + }
[Severity: High]
Can these plain reads cause data races and undefined behavior?
Since MultiColorDevice implements Sync, references can be safely shared across
threads. At the same time, the C LED subsystem can concurrently mutate these
fields asynchronously, for example via sysfs writes handled by
multi_intensity_store() or background state calculations in
led_mc_calc_color_components().
Concurrent unsynchronized read/write accesses to the same memory location,
where at least one is a write, are formal data races in Rust. Could these be
wrapped with proper atomic accesses or synchronization?
[ ... ]
> + // SAFETY:
> + // - `parent.as_ref().as_raw()` is guaranteed to be a pointer to a valid
> + // `device`.
> + // - `ptr` is guaranteed to be a pointer to an initialized `led_classdev_mc`.
> + to_result(unsafe {
> + bindings::led_classdev_multicolor_register_ext(
> + parent.as_ref().as_raw(),
> + ptr,
> + if self.name.is_none() {
> + &raw mut init_data
> + } else {
> + core::ptr::null_mut()
> + },
> + )
> + })?;
> +
> + subled_guard.dismiss();
> +
> + core::mem::forget(self.fwnode); // keep the reference count incremented
> +
> + Ok::<_, Error>(())
[Severity: High]
Can this sequence cause a reference leak or a use-after-free for the fwnode?
If a device name is provided, led_classdev_multicolor_register_ext() is called
with a null pointer for init_data to force the use of the provided name.
Consequently, the C LED subsystem does not copy the fwnode from init_data into
the device.
However, this code unconditionally calls core::mem::forget(self.fwnode).
If self.fwnode was Some, its reference count is leaked because
MultiColorDevice::drop() will later attempt to recover it using dev.fwnode(),
which will return None.
[ ... ]
> +#[pinned_drop]
> +impl<'bound, T: LedOps<Mode = MultiColor> + 'bound> PinnedDrop for MultiColorDevice<'bound, T> {
> + fn drop(self: Pin<&mut Self>) {
> + let raw = self.classdev.get();
> + // SAFETY: The existence of `self` guarantees that `self.classdev.get()` is a pointer to a
> + // valid `led_classdev_mc`.
> + let dev: &device::Device = unsafe { device::Device::from_raw((*raw).led_cdev.dev) };
> +
> + let _fwnode = dev
> + .fwnode()
> + // SAFETY: the reference count of `fwnode` has previously been
> + // incremented in `led::DeviceBuilder::build_multicolor`.
> + .map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) });
[Severity: High]
Following up on the previous observation, if self.fwnode was initially None,
but the C driver core later sets dev->fwnode (for example, via device_set_node
from an ACPI table or parent), could this code wrap that unowned pointer in
ARef::from_raw and improperly decrement its refcount upon destruction, causing
a use-after-free?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819-rust_leds-v23-0-2716a4ef89a4@posteo.de?part=3
next prev parent reply other threads:[~2026-08-19 19:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 18:58 [PATCH RESEND v23 0/3] rust: leds: add led classdev abstractions Markus Probst
2026-08-19 18:58 ` [PATCH RESEND v23 1/3] rust: leds: add basic " Markus Probst
2026-08-19 19:14 ` sashiko-bot
2026-08-19 18:58 ` [PATCH RESEND v23 2/3] rust: leds: add Mode trait Markus Probst
2026-08-19 19:11 ` sashiko-bot
2026-08-19 18:58 ` [PATCH RESEND v23 3/3] rust: leds: add multicolor classdev abstractions Markus Probst
2026-08-19 19:10 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-08-05 19:34 [PATCH RESEND v23 0/3] rust: leds: add led " Markus Probst via B4 Relay
2026-08-05 19:34 ` [PATCH RESEND v23 3/3] rust: leds: add multicolor " Markus Probst via B4 Relay
2026-08-05 19:34 ` Markus Probst
2026-08-05 20:52 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260819191032.DF95B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=markus.probst@posteo.de \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.