From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: ojeda@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v18 2/3] rust: leds: add Mode trait
Date: Sat, 30 May 2026 23:17:08 +0000 [thread overview]
Message-ID: <20260530231708.98DBE1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260531-rust_leds-v18-2-d07102ba5170@posteo.de>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Flawed fwnode reference count management in `led::Device` leads to refcount underflow or memory leaks.
- [High] Inverted lifetime bound `'bound: 'a` in `DeviceBuilder::build` allows the `Device` to outlive its name string, causing a Use-After-Free.
--
commit 79f921a7fb31b3f89538463530e40a222e664817
Author: Markus Probst <markus.probst@posteo.de>
rust: leds: add Mode trait
Add the led::Mode trait to allow for other types of led class devices
in led::LedOps.
> diff --git a/rust/kernel/led/normal.rs b/rust/kernel/led/normal.rs
> index 09244133f14c8..2ffe65bb9dc2c 100644
> --- a/rust/kernel/led/normal.rs
> +++ b/rust/kernel/led/normal.rs
[ ... ]
> @@ -20,7 +28,7 @@ pub struct Device<'bound, T: LedOps + 'bound> {
>
> impl<'a, S: DeviceBuilderState> DeviceBuilder<'a, S> {
> /// Registers a new [`Device`].
> - pub fn build<'bound: 'a, T: LedOps + 'bound>(
> + pub fn build<'bound: 'a, T: LedOps<Mode = Normal> + 'bound>(
[Severity: High]
Does this inverted lifetime bound ('bound: 'a) allow the device to outlive its
name string?
It appears that a caller can safely initialize a long-lived device (e.g.
'static) using a short-lived local string, because the returned PinInit does
not capture 'a.
Since the short-lived name pointer is assigned to the persistent C struct:
name: self.name.map_or(core::ptr::null(), CStrExt::as_char_ptr),
Does dropping the local string leave a dangling pointer in the C struct,
causing a use-after-free when the LED subsystem accesses led_cdev->name?
[Severity: High]
Can the fwnode reference count management here lead to underflows or memory
leaks?
In DeviceBuilder::build(), if self.fwnode is Some, its ARef is leaked:
core::mem::forget(self.fwnode); // keep the reference count incremented
But if it was None, no reference is leaked.
> self,
> parent: &'bound T::Bus,
> ops: impl PinInit<T, Error> + 'a,
[ ... ]
> @@ -209,7 +217,7 @@ impl<T: LedOps> Adapter<T> {
> }
>
> #[pinned_drop]
> -impl<'bound, T: LedOps + 'bound> PinnedDrop for Device<'bound, T> {
> +impl<'bound, T: LedOps<Mode = Normal> + 'bound> PinnedDrop for Device<'bound, T> {
[Severity: High]
When <Device as PinnedDrop>::drop attempts to recover the fwnode reference from
the mutable C field dev->fwnode:
let _fwnode = dev
.fwnode()
.map(|fwnode| unsafe { ARef::from_raw(NonNull::from(fwnode)) });
If self.fwnode was None, but the C core populates dev->fwnode (e.g. device_add
sets it to parent->fwnode), will PinnedDrop steal and drop a reference it does
not own, causing a refcount underflow?
Conversely, if self.fwnode was Some, but dev->fwnode is later cleared or
overwritten by C code, will the ARef never be dropped, causing a memory leak?
> 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
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260531-rust_leds-v18-0-d07102ba5170@posteo.de?part=2
next prev parent reply other threads:[~2026-05-30 23:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 22:49 [PATCH v18 0/3] rust: leds: add led classdev abstractions Markus Probst
2026-05-30 22:49 ` [PATCH v18 1/3] rust: leds: add basic " Markus Probst
2026-05-30 23:05 ` sashiko-bot
2026-05-30 23:48 ` Markus Probst
2026-05-30 22:49 ` [PATCH v18 2/3] rust: leds: add Mode trait Markus Probst
2026-05-30 23:17 ` sashiko-bot [this message]
2026-05-30 23:51 ` Markus Probst
2026-05-30 22:49 ` [PATCH v18 3/3] rust: leds: add multicolor classdev abstractions Markus Probst
2026-05-30 23:25 ` sashiko-bot
2026-05-31 0:36 ` Markus Probst
2026-05-31 7:55 ` Onur Özkan
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=20260530231708.98DBE1F00893@smtp.kernel.org \
--to=sashiko-bot@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.