From: Markus Probst <markus.probst@posteo.de>
To: sashiko-reviews@lists.linux.dev
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org, lee@kernel.org,
ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v2 4/4] leds: Add driver for disk leds in synology devices
Date: Fri, 04 Dec 2026 16:54:03 +0000 [thread overview]
Message-ID: <f8a7320433227d58450eb4e960e6ca424da1536c.camel@posteo.de> (raw)
In-Reply-To: <sashiko-outbox-249876@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 9106 bytes --]
On Fri, 2026-12-04 at 13:32 +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 5 potential
> issues to consider:
> - [High] leds: synology_disk: AB-BA deadlock and lockdep violation in
> update_modes()
> - [Medium] leds: synology_disk: unused DIM1 register constants fail
> CONFIG_WERROR builds
> - [Medium] leds: synology_disk: stale brightness after blink_set()
> breaks multi_intensity
> - [Medium] leds: synology_disk: premature delay and blink state mutation
> on SMBus error
> - [Low] leds: synology_disk: broken rustdoc link to nonexistent
> LedAddress symbol
> --
>
> commit 060d1125420b5346ac2845d99faa8ee654c4996c
> Author: Markus Probst <markus.probst@posteo.de>
>
> leds: Add driver for disk leds in synology devices
>
> This commit adds a Rust I2C multicolor LED driver for the ATmega1608 disk
> LED controller used in Synology NAS devices, along with Kconfig, Makefile,
> and MAINTAINERS entries.
>
> > diff --git a/drivers/leds/leds_synology_disk.rs b/drivers/leds/leds_synology_disk.rs
> > new file mode 100644
> > index 0000000000000..6ae60bc89cac8
> > --- /dev/null
> > +++ b/drivers/leds/leds_synology_disk.rs
>
> [ ... ]
>
> > +//! The controller has 6 8-bit i2c registers for led modes. See [`LedAddress`].
>
> [Severity: Low]
> This rustdoc link points to LedAddress, which does not exist in this
> module and triggers a broken_intra_doc_links warning. Should this
> reference Modes or LedAddressData instead?
true positive.
>
> [ ... ]
>
> > + DIM0_DELAY: u8 @ 0x02;
> > + DIM0_BRIGHTNESS: u8 @ 0x03;
> > + DIM1_DELAY: u8 @ 0x04;
> > + DIM1_BRIGHTNESS: u8 @ 0x05;
>
> [Severity: Medium]
> Will DIM1_DELAY and DIM1_BRIGHTNESS break builds with CONFIG_WERROR=y or
> W=e?
>
> The register! macro expands these into private const items without
> #[allow(dead_code)], and neither constant is referenced in the driver.
> Adding #[expect(dead_code)] (as done on LedMode::Dim1) or removing them
> would avoid dead_code warnings becoming build errors.
It doesn't, but I removed it anyway now.
>
> [ ... ]
>
> > + fn brightness_set<'bound>(
> > + self: &led::MultiColorDevice<'bound, Self>,
> > + brightness: u32,
> > + ) -> Result<()> {
> > + let mut blink = self.blink.lock();
> > +
> > + if brightness == 0 {
> > + *blink = false;
> > + }
> > +
> > + self.update_modes(|subled_info| {
> > + if subled_info.brightness() == 0 {
> > + LedMode::Off
> > + } else if *blink {
> > + LedMode::Dim0
> > + } else {
> > + LedMode::On
> > + }
> > + })?;
> > +
> > + Ok(())
> > + }
> > +
> > + fn blink_set<'bound>(
> > + self: &led::MultiColorDevice<'bound, Self>,
> > + delay_on: &mut usize,
> > + delay_off: &mut usize,
> > + ) -> Result<()> {
> > + let mut blink = self.blink.lock();
> > + if *delay_on == 0 && *delay_off != 0 {
> > + *blink = false;
> > + self.update_modes(|_subled_info| LedMode::Off)?;
> > + return Ok(());
> > + }
> > + if *delay_off == 0 && *delay_on != 0 {
> > + *blink = false;
> > + self.update_modes(|subled_info| {
> > + if subled_info.intensity() == 0 {
> > + LedMode::Off
> > + } else {
> > + LedMode::On
> > + }
> > + })?;
> > + return Ok(());
> > + }
> > +
> > + *delay_on = 90;
> > + *delay_off = 90;
> > +
> > + self.update_modes(|subled_info| {
> > + if subled_info.intensity() == 0 {
> > + LedMode::Off
> > + } else {
> > + LedMode::Dim0
> > + }
> > + })?;
> > + *blink = true;
> > +
> > + Ok(())
> > + }
>
> [Severity: Medium]
> Can writing multi_intensity cancel hardware blinking and turn the LED off
> when blinking starts from brightness 0?
>
> After probe (or after switching triggers in __led_trigger_set()),
> led_cdev->brightness is 0. When blink_set() enables hardware blinking and
> returns Ok(()), led_blink_setup() leaves LED_BLINK_SW clear and does not
> update led_cdev->brightness. A later sysfs write to multi_intensity then
> re-applies that stale brightness:
>
> drivers/leds/led-class-multicolor.c:multi_intensity_store() {
> ...
> if (!test_bit(LED_BLINK_SW, &led_cdev->work_flags))
> led_set_brightness(led_cdev, led_cdev->brightness);
> ...
> }
>
> That calls brightness_set(0), which clears *blink and turns all subleds
> off. The same desynchronization happens in the delay_on == 0 and
> delay_off == 0 branches above, since returning Ok(()) without updating
> led_cdev->brightness leaves subsequent multi_intensity writes replaying
> the old on/off state.
The described behaviour is not an issue specific to this driver.
False positive.
>
> [Severity: Medium]
> Should *delay_on and *delay_off in blink_set() only be overwritten after
> update_modes() succeeds?
>
> When blink_set() returns an error, led_blink_setup() falls back to
> led_set_software_blink(led_cdev, *delay_on, *delay_off). Setting both to
> 90 before the fallible SMBus write discards the caller's requested delays
> (and the 500 ms default when both were 0), driving a 90 ms software blink
> timer onto an already failing I2C bus.
>
> Similarly, clearing *blink = false before update_modes()? in
> brightness_set() and the two zero-delay branches of blink_set() leaves the
> cached blink flag out of sync with the hardware registers if the SMBus
> write fails.
Edge case, but true positive.
>
> [ ... ]
>
> > + fn update_modes<F: FnMut(&led::MultiColorSubLed) -> LedMode>(
> > + self: &led::MultiColorDevice<'_, Self>,
> > + mut func: F,
> > + ) -> Result<()> {
> > + let mut guards = core::array::from_fn::<_, LED_ADDRESSES, _>(|_| None);
> > +
> > + for (subled, subled_info) in self.subleds.iter().zip(self.subleds()) {
> > + let (_, goal, _) = guards[subled.addr.addr.index()].get_or_insert_with(|| {
> > + let guard = subled.addr.data.lock();
> > + (subled.addr.addr, *guard, guard)
> > + });
> > + let mode = (func)(subled_info);
> > +
> > + *goal = match *subled.id {
> > + 0 => goal.with_led1(mode),
> > + 1 => goal.with_led2(mode),
> > + 2 => goal.with_led3(mode),
> > + 3 => goal.with_led4(mode),
> > + _ => unreachable!(),
> > + };
> > + }
> > +
> > + let io = self.client.smbus_io();
> > + for (addr, goal, mut current) in guards.into_iter().flatten() {
> > + if goal != *current {
> > + io.try_write(addr, goal).inspect_err(|err| {
> > + dev_err!(
> > + self.client.as_ref(),
> > + "failed to write {:#2x}: {err:?}\n",
> > + addr.offset()
> > + );
> > + })?;
> > + *current = goal;
> > + }
> > + }
> > + Ok(())
> > + }
>
> [Severity: High]
> Can update_modes() cause an ABBA deadlock and trigger a lockdep recursive
> locking splat when a multicolor LED spans two mode registers?
>
> probe() stores subleds in raw DT child order without sorting by register
> index, and update_modes() holds every acquired LedAddressData::data mutex
> simultaneously across the blocking SMBus writes. Because LED callbacks can
> run concurrently (for example led_delay_on_store() calling led_blink_set()
> synchronously in sysfs context while leds_wq runs set_brightness_delayed()),
> two LEDs referencing the same two registers in opposite DT order deadlock:
>
> CPU0 CPU1
> ---- ----
> lock(&addrs[0].data)
> lock(&addrs[1].data)
> lock(&addrs[1].data)
> lock(&addrs[0].data)
>
> *** DEADLOCK ***
>
> CPU0: led_delay_on_store() -> led_blink_set() -> update_modes()
> CPU1: set_brightness_delayed() -> brightness_set() -> update_modes()
>
> In addition, init() creates all six mutexes with a single new_mutex!()
> call in a loop, so they share one static lockdep class; even a single
> multicolor LED spanning two registers will trigger a lockdep recursive
> locking warning on the second lock().
>
> Since each register is written in an independent SMBus transfer, using a
> single shared Mutex<[Modes; LED_ADDRESSES]> (or locking and writing one
> register at a time) avoids the deadlock, the lockdep warning, and holding
> multiple register locks across blocking I/O.
true positive.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 870 bytes --]
prev parent reply other threads:[~2026-12-04 16:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 12:21 [PATCH v2 0/4] leds: Add driver for disk leds in synology devices Markus Probst
2026-12-04 12:21 ` [PATCH v2 1/4] dt-bindings: leds: Add synology disk led controller Markus Probst
2026-12-04 12:35 ` sashiko-bot
2026-12-04 12:21 ` [PATCH v2 2/4] rust: io: Add `RegisterArrayLoc::index` Markus Probst
2026-12-04 12:30 ` sashiko-bot
2026-12-04 12:21 ` [PATCH v2 3/4] rust: io: Implement Copy for RegisterArrayLoc Markus Probst
2026-12-04 12:33 ` sashiko-bot
2026-12-04 13:38 ` Gary Guo
2026-12-04 13:42 ` Markus Probst
2026-12-04 12:22 ` [PATCH v2 4/4] leds: Add driver for disk leds in synology devices Markus Probst
2026-12-04 13:32 ` sashiko-bot
2026-12-04 16:54 ` Markus Probst [this message]
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=f8a7320433227d58450eb4e960e6ca424da1536c.camel@posteo.de \
--to=markus.probst@posteo.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gary@garyguo.net \
--cc=lee@kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=robh@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