Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
Cc: ojeda@kernel.org, gary@garyguo.net, linux-pci@vger.kernel.org,
	linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v26 3/4] rust: leds: Add multicolor classdev abstractions
Date: Wed, 30 Sep 2026 13:17:48 +0000	[thread overview]
Message-ID: <20260930131749.5F2D51F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260930-rust_leds-v26-3-83837331020e@posteo.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] rust: leds: data race and UB via plain reads in MultiColorSubLed
--

commit 8041b99a2f954026eb99d9bedff3e1091196ee48
Author: Markus Probst <markus.probst@posteo.de>

rust: leds: Add multicolor classdev abstractions

This commit implements the abstractions needed for multicolor led class
devices. It introduces the led mode implementation, safe wrappers around
mc_subled and led_classdev_mc, and a builder function for registration.

> diff --git a/rust/kernel/led/multicolor.rs b/rust/kernel/led/multicolor.rs
> new file mode 100644
> index 0000000000000..309487bdf38aa
> --- /dev/null
> +++ b/rust/kernel/led/multicolor.rs
[ ... ]
> +    /// The intensity of the sub led.
> +    #[inline]
> +    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() }

[Severity: High]
Does this unsynchronized plain read introduce a data race and undefined
behavior?

In the Rust memory model, concurrent non-atomic reads and writes constitute
a data race, which is strictly undefined behavior. A sysfs write to
multi_intensity_store can lock led_access and modify
subled_info[i].intensity.

Concurrently, the driver's workqueue (set_brightness_delayed) or an atomic
trigger could execute brightness_set without holding led_access. When this
happens, the Rust driver reads the intensity at the exact same time it is
being written by the C core.

Could we use core::ptr::read_volatile() here to emulate READ_ONCE()
semantics and prevent the compiler from optimizing under the assumption
that the value does not change?

> +    }
> +
> +    /// 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]
Similarly, does this plain read risk the same data race if concurrent
trigger events modify the brightness?

Replacing this read with core::ptr::read_volatile() would emulate
READ_ONCE() and safely mitigate the undefined behavior.

> +    }
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260930-rust_leds-v26-0-83837331020e@posteo.de?part=3

  reply	other threads:[~2026-09-30 13:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 13:05 [PATCH v26 0/4] rust: leds: Add led classdev abstractions Markus Probst
2026-09-30 13:05 ` [PATCH v26 1/4] rust: leds: Add basic " Markus Probst
2026-09-30 13:18   ` sashiko-bot
2026-09-30 13:05 ` [PATCH v26 2/4] rust: leds: Add Mode trait Markus Probst
2026-09-30 13:10   ` sashiko-bot
2026-09-30 13:05 ` [PATCH v26 3/4] rust: leds: Add multicolor classdev abstractions Markus Probst
2026-09-30 13:17   ` sashiko-bot [this message]
2026-10-09 18:52   ` Boqun Feng
2026-09-30 13:05 ` [PATCH v26 4/4] MAINTAINERS: rust: leds: Add rust abstraction entry Markus Probst
2026-10-08 11:32 ` [PATCH v26 0/4] rust: leds: Add led classdev abstractions Markus Probst

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=20260930131749.5F2D51F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gary@garyguo.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox