Linux LED subsystem development
 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 v19 2/2] platform: Add initial synology microp driver
Date: Fri, 04 Dec 2026 13:34:55 +0000	[thread overview]
Message-ID: <sashiko-outbox-249879@kernel.org> (raw)
In-Reply-To: <20261204-synology_microp_initial-v19-2-33fd992bf049@posteo.de>

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] platform: synology_microp: unbounded serdev wait in
  Command::write()
- [Medium] platform/synology_microp: Kconfig allows modular LEDS_CLASS
  breaking Rust build
- [Medium] platform/synology_microp: Command::write() ignores short
  writes from write_all()
- [Medium] platform/synology_microp: blink state and delays mutated
  before write succeeds
- [Medium] platform/synology_microp: multi_intensity turns off blinking
  status LED
- [Medium] rust: led: aliasing &mut usize in blink_set_callback() from
  ledtrig-timer
- [Low] platform/synology_microp: deprecated vendor prefix and
  non-standard LED name
- [Low] platform/synology_microp: commit message omits supported eSATA
  LED
--

commit 5e1e8cacbaf185da4acf3731fa20dd161b67fc7a
Author: Markus Probst <markus.probst@posteo.de>

platform: Add initial synology microp driver

This commit adds an initial Rust serdev driver for the Synology NAS
microcontroller, exposing its power, status, alert, USB, and eSATA LEDs
through the kernel LED class abstractions.

> It currently only supports controlling of the power led, status led, alert
> led and usb led.

[Severity: Low]
This isn't a bug, but the commit message omits the eSATA LED, which this
patch also implements for synology,ds710p-microp.

[ ... ]

> diff --git a/drivers/platform/synology_microp/Kconfig b/drivers/platform/synology_microp/Kconfig
> new file mode 100644
> index 0000000000000..8878cfb7bcddb
> --- /dev/null
> +++ b/drivers/platform/synology_microp/Kconfig
> @@ -0,0 +1,13 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +config SYNOLOGY_MICROP
> +	tristate "Synology Microp driver"
> +	depends on LEDS_CLASS && LEDS_CLASS_MULTICOLOR

[Severity: Medium]
Can this break the build when CONFIG_LEDS_CLASS=m or
CONFIG_LEDS_CLASS_MULTICOLOR=m with CONFIG_SYNOLOGY_MICROP=m?

Both LEDS_CLASS and LEDS_CLASS_MULTICOLOR are tristate, but
rust/kernel/lib.rs gates pub mod led on CONFIG_LEDS_CLASS="y" and
rust/kernel/led.rs gates mod multicolor on
CONFIG_LEDS_CLASS_MULTICOLOR="y".  In modular configs such as
allmodconfig, the driver fails to compile with unresolved kernel::led
imports.

Changing the dependency to LEDS_CLASS=y && LEDS_CLASS_MULTICOLOR=y
prevents the broken configuration.

[ ... ]

> diff --git a/drivers/platform/synology_microp/command.rs b/drivers/platform/synology_microp/command.rs
> new file mode 100644
> index 0000000000000..490719490391c
> --- /dev/null
> +++ b/drivers/platform/synology_microp/command.rs
> @@ -0,0 +1,54 @@

[ ... ]

> +impl Command {
> +    pub(crate) fn write(self, dev: &serdev::Device<Bound>) -> Result {
> +        dev.write_all(
> +            match self {

[ ... ]

> +                Self::AlertLed(led::State::On) => &[0x4C, 0x41, 0x31],
> +                Self::AlertLed(led::State::Blink) => &[0x4C, 0x41, 0x32],
> +                Self::AlertLed(led::State::Off) => &[0x4C, 0x41, 0x33],
> +
> +                Self::UsbLed(led::State::On) => &[0x40],
> +                Self::UsbLed(led::State::Blink) => &[0x41],
> +                Self::UsbLed(led::State::Off) => &[0x42],
> +
> +                Self::EsataLed(led::State::On) => &[0x4C, 0x45, 0x31],
> +                Self::EsataLed(led::State::Blink) => &[0x4C, 0x45, 0x32],
> +                Self::EsataLed(led::State::Off) => &[0x4C, 0x45, 0x33],
> +            },
> +            0,
> +        )?;

[Severity: Medium]
Can Command::write() silently treat a short write of a 3-byte AlertLed
or EsataLed command as success?

serdev::Device::write_all() wraps serdev_device_write(), which returns
the positive partial byte count as Ok(written) if a signal interrupts
the wait after at least one byte is accepted.  Discarding that count
leaves a truncated prefix on the serial line and releases
serdev->write_lock, allowing subsequent LED commands to interleave and
desynchronize the microcontroller parser.

Checking that the returned count equals the slice length (and retrying
or returning an error otherwise) avoids silent truncation.

> +        dev.wait_until_sent(0);

[Severity: High]
Can passing timeout 0 to dev.write_all() and dev.wait_until_sent()
deadlock the global leds_wq workqueue when the parent UART is unbound or
removed?

Timeout 0 is translated to MAX_SCHEDULE_TIMEOUT in both
serdev_device_write() and tty_wait_until_sent().  During UART removal,
serial_core_unregister_port() marks the port UPF_DEAD before
unregistering the serdev child, and PrivateData::drop() drops
SynologyMicropDriver before calling serdev_device_close():

UART removal thread                   leds_wq kworker
-------------------                   ---------------
serial_core_unregister_port()
  port->flags |= UPF_DEAD
  serial_core_remove_one_port()
    ... -> led_classdev_unregister()
      led_set_brightness(LED_OFF)
      flush_work(set_brightness_work)
                                      set_brightness_delayed()
                                        Command::write()
                                          uart_write() -> kfifo_in()
                                          __uart_start() (skips, UPF_DEAD)
                                          tty_wait_until_sent(tty, 0)
                                            <-- sleeps forever

Because __uart_start() returns early on UPF_DEAD, the queued byte never
drains and tty_wait_until_sent() sleeps indefinitely while the removal
thread waits in flush_work(), wedging leds_wq and holding serial_core's
port_mutex.  The same unbounded wait applies to dev.write_all(..., 0) if
the FIFO fills, or if an LED trigger fires while the parent UART is
suspended.

Passing finite timeouts to both dev.write_all() and
dev.wait_until_sent() prevents the permanent hang.

> diff --git a/drivers/platform/synology_microp/led.rs b/drivers/platform/synology_microp/led.rs
> new file mode 100644
> index 0000000000000..170e385548fc3
> --- /dev/null
> +++ b/drivers/platform/synology_microp/led.rs
> @@ -0,0 +1,300 @@

[ ... ]

> +                status <- led::DeviceBuilder::new()
> +                    .color(led::Color::Multi)
> +                    .name(c"synology:multicolor:status")

[ ... ]

> +                                .name(c"synology:green:esata")

[Severity: Low]
Should these LED names drop the synology: vendor prefix and use a
standard LED_FUNCTION_* name instead of esata?

Documentation/leds/leds-class.rst deprecates vendor prefixes in LED
device names and expects the function part to come from
include/dt-bindings/leds/common.h, which does not define esata.  All
five LEDs registered in Data::register() currently use the synology:
prefix.

[ ... ]

> +    fn blink_set<'bound>(
> +        self: &led::Device<'bound, Self>,
> +        delay_on: &mut usize,
> +        delay_off: &mut usize,
> +    ) -> Result<()> {

[Severity: Medium]
Does implementing LedOps::blink_set() here expose aliasing &mut usize
undefined behavior in rust/kernel/led/?

This driver adds the first in-tree implementations of
LedOps::blink_set() (in LedHandler and StatusLedHandler), instantiating
Adapter::blink_set_callback() in rust/kernel/led/normal.rs and
rust/kernel/led/multicolor.rs.  Both callbacks form
unsafe { &mut *delay_on } and unsafe { &mut *delay_off } assuming
exclusive access, but led_delay_on_store() and led_delay_off_store() in
drivers/leds/trigger/ledtrig-timer.c pass &led_cdev->blink_delay_off and
&led_cdev->blink_delay_on to led_blink_set() without locking.

Two concurrent writes to delay_on (or a write racing with a sysfs read)
create aliasing &mut usize references and data races on those fields
before self.blink.lock() is acquired.

> +        let mut blink = self.blink.lock();
> +
> +        (self.command)(if *delay_on == 0 && *delay_off != 0 {
> +            *blink = false;
> +
> +            State::Off
> +        } else if *delay_on != 0 && *delay_off == 0 {
> +            *blink = false;
> +
> +            State::On
> +        } else {
> +            *blink = true;
> +            *delay_on = BLINK_DELAY.as_millis() as usize;
> +            *delay_off = BLINK_DELAY.as_millis() as usize;
> +
> +            State::Blink
> +        })
> +        .write(self.dev)
> +    }

[Severity: Medium]
Does mutating *blink, *delay_on, and *delay_off before .write(self.dev)
succeeds corrupt software-blink fallback on write errors?

If Command::write() fails (for example with -ERESTARTSYS),
led_blink_setup() in drivers/leds/led-core.c falls back to
led_set_software_blink() using the already-overwritten 167 ms delays
instead of the requested or default delays.  Because *blink was already
set to true, each software-blink ON tick then calls brightness_set(1)
and sends State::Blink instead of State::On.

StatusLedHandler::blink_set() has the same issue, and both
LedHandler::brightness_set() and StatusLedHandler::brightness_set()
clear *blink before .write(self.dev) succeeds.  Updating *blink and the
delay out-parameters only after .write(self.dev)? returns Ok(()) keeps
driver state in sync with the hardware.

[ ... ]

> +    fn brightness_set<'bound>(
> +        self: &led::MultiColorDevice<'bound, Self>,
> +        brightness: u32,
> +    ) -> Result<()> {
> +        let mut blink = self.blink.lock();
> +        if brightness == 0 {
> +            *blink = false;
> +        }
> +
> +        let amber_brightness = self.subleds()[1].brightness();

[ ... ]

> +    fn blink_set<'bound>(
> +        self: &led::MultiColorDevice<'bound, Self>,
> +        delay_on: &mut usize,
> +        delay_off: &mut usize,
> +    ) -> Result<()> {
> +        let mut blink = self.blink.lock();
> +
> +        let amber_intensity = self.subleds()[1].intensity();
> +
> +        let (color, subled_intensity) = if amber_intensity == 0 {
> +            (StatusLedColor::Green, self.subleds()[0].intensity())
> +        } else {
> +            (StatusLedColor::Amber, amber_intensity)
> +        };

[Severity: Medium]
Does writing multi_intensity turn off the status LED when hardware
blinking was started from brightness 0?

Data::register() leaves the status LED's initial brightness at 0 with
Green intensity 1.  When the timer trigger starts hardware blinking,
StatusLedHandler::blink_set() uses the subled intensities to start
blinking while led_cdev->brightness stays 0.  If userspace then writes
multi_intensity to switch the blinking color to amber,
multi_intensity_store() calls led_set_brightness(led_cdev, 0), which
runs brightness_set(0), clears *blink, and sends State::Off.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-synology_microp_initial-v19-0-33fd992bf049@posteo.de?part=2

      reply	other threads:[~2026-12-04 13:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 12:26 [PATCH v19 0/2] Introduce Synology Microp driver Markus Probst
2026-12-04 12:26 ` [PATCH v19 1/2] dt-bindings: embedded-controller: Add synology microp devices Markus Probst
2026-12-04 12:37   ` sashiko-bot
2026-12-04 12:26 ` [PATCH v19 2/2] platform: Add initial synology microp driver Markus Probst
2026-12-04 13:34   ` sashiko-bot [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=sashiko-outbox-249879@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