Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Markus Probst" <markus.probst@posteo.de>
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 2/2] leds: add driver for disk leds in synology devices
Date: Wed, 02 Dec 2026 15:38:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-246118@kernel.org> (raw)
In-Reply-To: <20261202-synology_disk_leds-v1-2-53249fd3a2ad@posteo.de>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] leds: synology_disk: missing I2C=y Kconfig dependency breaks
  modular I2C build
- [Medium] leds: synology_disk: uninitialized mode registers desync
  cache in probe()
- [Medium] leds: synology_disk: premature register clear in unbind()
  before LED drop
- [Medium] leds: synology_disk: multi_intensity write cancels hardware
  blink_set()
- [Low] leds: synology_disk: unsorted Makefile entry and non-standard
  commit subject
--

commit 89384e625f4f23cc76bff85dcf0243a699d6bc61
Author: Markus Probst <markus.probst@posteo.de>

leds: add driver for disk leds in synology devices

This commit adds a Rust I2C LED driver for the Atmega1608 disk LED
controller used in Synology NAS devices.

> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
> index 7ec2c8d785426..34cf2a3f0baca 100644
> --- a/drivers/leds/Kconfig
> +++ b/drivers/leds/Kconfig
> @@ -332,6 +332,15 @@ config LEDS_WRAP
>  	help
>  	  This option enables support for the PCEngines WRAP programmable LEDs.
>  
> +config LEDS_SYNOLOGY_DISK
> +	tristate "LED Support for disk leds used in Synology devices"
> +	depends on LEDS_CLASS && LEDS_CLASS_MULTICOLOR
> +	depends on I2C

[Severity: Medium]
Should this depend on I2C=y rather than I2C?

The Rust I2C abstractions in rust/kernel/lib.rs are only built when
CONFIG_I2C=y:

rust/kernel/lib.rs {
    ...
#[cfg(CONFIG_I2C = "y")]
pub mod i2c;
    ...
}

When CONFIG_I2C=m and CONFIG_LEDS_SYNOLOGY_DISK=m, compiling this driver
fails with unresolved imports for kernel::i2c and
kernel::module_i2c_driver!.

> diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
> index 4d4b089156e24..466549f65f9ca 100644
> --- a/drivers/leds/Makefile
> +++ b/drivers/leds/Makefile
> @@ -101,6 +101,7 @@ obj-$(CONFIG_LEDS_UPBOARD)		+= leds-upboard.o
>  obj-$(CONFIG_LEDS_WM831X_STATUS)	+= leds-wm831x-status.o
>  obj-$(CONFIG_LEDS_WM8350)		+= leds-wm8350.o
>  obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
> +obj-$(CONFIG_LEDS_SYNOLOGY_DISK)	+= leds_synology_disk.o

[Severity: Low]
This isn't a bug, but the LED Platform Drivers section of
drivers/leds/Makefile asks to be kept sorted alphabetically (between
CONFIG_LEDS_SUNFIRE and CONFIG_LEDS_SYSCON).  Also, LED subsystem commit
subjects normally follow the "leds: <driver>: <Capitalized description>"
convention.

> diff --git a/drivers/leds/leds_synology_disk.rs b/drivers/leds/leds_synology_disk.rs
> new file mode 100644
> index 0000000000000..1f339e2e429e5
> --- /dev/null
> +++ b/drivers/leds/leds_synology_disk.rs
[ ... ]
> +    fn probe<'bound>(
> +        idev: &'bound I2cClient<Core<'_>>,
> +        _id_info: Option<&'bound Self::IdInfo>,
> +    ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
[ ... ]
> +        let addr = Arc::new(
> +            KBox::pin_slice::<_, _, Error, Error>(
> +                |index| {
> +                    try_pin_init!(LedAddressData {
> +                        addr: LedAddress::VALUES[index],
> +                        data <- new_mutex!(0u8),
> +                    })
> +                },
> +                LedAddress::VALUES.len(),
> +                GFP_KERNEL,
> +            )?,
> +            GFP_KERNEL,
> +        )?;
[ ... ]
> +        idev.smbus_io()
> +            .try_write8(0, 0x01)
> +            .inspect_err(|err| dev_err!(dev, "unable to remove led mask: {err:?}\n"))?;
> +
> +        Ok(SynologyDiskLedDriver { _leds: leds })
> +    }

[Severity: Medium]
Can LedAddressData::data start out of sync with the hardware mode
registers 0x06..=0x0B in probe()?

LedAddressData::data is initialized to 0u8, and probe() unmasks register
0x01 without clearing or reading registers 0x06..=0x0B.  If the
bootloader or a previous boot left non-zero mode bits in 0x06..=0x0B,
those physical LEDs turn on or blink as soon as 0x01 is unmasked while
their LED class devices report brightness 0.  Calling brightness_set(0)
then cannot turn them off because update_modes() skips the SMBus write
when goal == *current (0 == 0).

> +
> +    fn unbind<'bound>(dev: &'bound I2cClient<Core<'_>>, _this: Pin<&Self::Data<'bound>>) {
> +        let _ = dev
> +            .smbus_io()
> +            .try_write8(1, 0x01)
> +            .inspect_err(|err| dev_err!(dev.as_ref(), "unable to set led mask: {err:?}\n"));
> +
> +        for addr in LedAddress::VALUES {
> +            let _ = dev
> +                .smbus_io()
> +                .try_write8(0, addr as usize)
> +                .inspect_err(|err| {
> +                    dev_err!(
> +                        dev.as_ref(),
> +                        "Unable to turn off leds at address {:#2x}: {err:?}\n",
> +                        (addr as u8)
> +                    )
> +                });
> +        }
> +    }
> +}

[Severity: Medium]
Does unbind() clear hardware registers before _leds are unregistered?

In the Rust driver lifecycle, i2c::Adapter::remove_callback() runs
unbind() before Registration::post_unbind_callback() drops
SynologyDiskLedDriver and its _leds vector.  While unbind() writes
registers 0x01 and 0x06..=0x0B without locking or updating
LedAddressData::data, active triggers or sysfs writes can still call
update_modes() concurrently.  Then, when post_unbind_callback() drops
each MultiColorDevice, led_classdev_unregister() calls brightness_set(0)
-> update_modes(), which compares against the stale pre-unbind cache in
LedAddressData::data and writes stale non-zero bits of sibling LEDs
sharing a register back to hardware.

[ ... ]

> +#[vtable]
> +impl led::LedOps for Led<'_> {
> +    type Mode = led::MultiColor;
> +    const BLOCKING: bool = true;
> +    const MAX_BRIGHTNESS: u32 = 1;
> +
> +    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]
Does writing to multi_intensity while hardware blinking is active turn
the LED off instead of changing its color?

When blink_set() enables hardware blinking (for example when the timer
trigger is attached), led_blink_setup() does not set LED_BLINK_SW and
leaves led_cdev->brightness at 0.  A later write to multi_intensity runs:

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);
    ...
}

Because led_cdev->brightness is 0, this calls Led::brightness_set(0),
which sets *blink = false and turns all sub-LEDs off.  Likewise, handling
*delay_on == 0 or *delay_off == 0 directly in blink_set() instead of
letting led_set_software_blink() update led_cdev->brightness leaves
led_cdev->brightness stale when multi_intensity is written later.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-synology_disk_leds-v1-0-53249fd3a2ad@posteo.de?part=2

  reply	other threads:[~2026-12-02 15:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:21 [PATCH 0/2] leds: add driver for disk leds in synology devices Markus Probst
2026-12-02 15:21 ` [PATCH 1/2] dt-bindings: leds: Add synology disk led controller Markus Probst
2026-12-02 15:29   ` sashiko-bot
2026-12-02 15:21 ` [PATCH 2/2] leds: add driver for disk leds in synology devices Markus Probst
2026-12-02 15:38   ` sashiko-bot [this message]
2026-12-02 15:47     ` 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=sashiko-outbox-246118@kernel.org \
    --to=sashiko-bot@kernel.org \
    --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=markus.probst@posteo.de \
    --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