* [PATCH v2 0/4] leds: Add driver for disk leds in synology devices
@ 2026-12-04 12:21 Markus Probst
2026-12-04 12:21 ` [PATCH v2 1/4] dt-bindings: leds: Add synology disk led controller Markus Probst
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Markus Probst @ 2026-12-04 12:21 UTC (permalink / raw)
To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core,
Markus Probst
Yet another user for the rust led abstractions.
This adds a driver to control the disk leds on synology devices.
Dependencies:
- LED Rust Abstraction [1]
- Rust I2C SMBus IO backend implementation [2]
[1] https://lore.kernel.org/rust-for-linux/20261113-rust_leds-v28-0-b8cf2f74fa57@posteo.de/
[2]
https://lore.kernel.org/rust-for-linux/20261201165508.39336-1-muchamadcoirulanwar@gmail.com/
(patch 1+2)
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
Changes in v2:
- fixed issues reported by Sashiko:
- add missing I2C=y dependency in Kconfig
- remove register clean in unbind
- clear led modes on probe
- sort Makefile
- capitalize subject line
- dt binding rejecting hexadecimal numbers in unit name
- use () as type for IdInfo
- add missing LEDS_CLASS=y && LEDS_CLASS_MULTICOLOR=y dependency in
Kconfig
- refactored to use register! (2 additional patches required)
- move initialization code into own init function
- move unbind() code into Drop
- adapt to rust_leds v29
- Link to v1: https://patch.msgid.link/20261202-synology_disk_leds-v1-0-53249fd3a2ad@posteo.de
---
Markus Probst (4):
dt-bindings: leds: Add synology disk led controller
rust: io: Add `RegisterArrayLoc::index`
rust: io: Implement Copy for RegisterArrayLoc
leds: Add driver for disk leds in synology devices
.../bindings/leds/synology,disk-leds.yaml | 151 +++++++
MAINTAINERS | 7 +
drivers/leds/Kconfig | 9 +
drivers/leds/Makefile | 1 +
drivers/leds/leds_synology_disk.rs | 453 +++++++++++++++++++++
rust/kernel/io/register.rs | 13 +
6 files changed, 634 insertions(+)
---
base-commit: c8cbaa094f4f7cc4e4d5a1e3ea7be5dfb362dcbb
change-id: 20261122-synology_disk_leds-182da42b8902
prerequisite-change-id: 20251114-rust_leds-a959f7c2f7f9:v29
prerequisite-patch-id: 89aa72aea271e8b3d6dbaffe46d93c1bff4014a9
prerequisite-patch-id: 9d6a38e90660f59652540ad258808c8bfa6c0d8c
prerequisite-patch-id: 8c8dcfb3cca3fd63b704edc30737268d525d0b54
prerequisite-patch-id: 9976190872fe26c2a980c66a4ebc050fd2bcaf71
prerequisite-message-id: 20261201165508.39336-1-muchamadcoirulanwar@gmail.com
prerequisite-patch-id: 8741958d13c628fd7b19b96c3b3dcbbd30ddfb48
prerequisite-patch-id: 13b003555af95fc3e45de60a39e9a0ff8aabd1bd
prerequisite-patch-id: f28d13f870e227b99920bc10f9990d8f713f8c00
prerequisite-patch-id: 5ede68001055ff3faddde5d3173f84ebce2f3e92
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/4] dt-bindings: leds: Add synology disk led controller
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 ` 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
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Markus Probst @ 2026-12-04 12:21 UTC (permalink / raw)
To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core,
Markus Probst
Add devicetree bindings for the synology disk led controller. It uses
the Atmega1608 microcontroller with I2C interface.
The led controller supports up to 24 leds. It is common that multiple leds
in Synology devices share the same slot and thus are grouped as multicolor
led.
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
.../bindings/leds/synology,disk-leds.yaml | 151 +++++++++++++++++++++
1 file changed, 151 insertions(+)
diff --git a/Documentation/devicetree/bindings/leds/synology,disk-leds.yaml b/Documentation/devicetree/bindings/leds/synology,disk-leds.yaml
new file mode 100644
index 000000000000..2c2e1e35c265
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/synology,disk-leds.yaml
@@ -0,0 +1,151 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/synology,disk-leds.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Synology disk led controller
+
+maintainers:
+ - Markus Probst <markus.probst@posteo.de>
+
+description: |
+ Led controller used for disk leds in Synology devices. It uses the
+ Atmega1608 microcontroller with I2C interface.
+
+properties:
+ compatible:
+ const: synology,disk-leds
+
+ reg:
+ maxItems: 1
+
+patternProperties:
+ "^disk-[0-9]+$":
+ type: object
+ $ref: leds-class-multicolor.yaml#
+ unevaluatedProperties: false
+
+ properties:
+ "#address-cells":
+ const: 1
+
+ "#size-cells":
+ const: 0
+
+ patternProperties:
+ "^led@[0-9a-f]+$":
+ type: object
+ additionalProperties: false
+
+ properties:
+ reg:
+ description: Index of the LED.
+ minimum: 0
+ maximum: 23
+
+ color:
+ description: Color of the LED.
+ $ref: /schemas/types.yaml#/definitions/uint32
+ minimum: 0
+ maximum: 14
+
+ required:
+ - reg
+ - color
+
+ required:
+ - "#address-cells"
+ - "#size-cells"
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/leds/common.h>
+
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led-controller@60 {
+ compatible = "synology,disk-leds";
+ reg = <0x60>;
+
+ disk-1 {
+ function = LED_FUNCTION_DISK;
+ function-enumerator = <1>;
+ color = <LED_COLOR_ID_MULTI>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_GREEN>;
+ };
+
+ led@1 {
+ reg = <1>;
+ color = <LED_COLOR_ID_AMBER>;
+ };
+ };
+
+ disk-2 {
+ function = LED_FUNCTION_DISK;
+ function-enumerator = <2>;
+ color = <LED_COLOR_ID_MULTI>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@2 {
+ reg = <2>;
+ color = <LED_COLOR_ID_GREEN>;
+ };
+
+ led@3 {
+ reg = <3>;
+ color = <LED_COLOR_ID_AMBER>;
+ };
+ };
+
+ disk-3 {
+ function = LED_FUNCTION_DISK;
+ function-enumerator = <3>;
+ color = <LED_COLOR_ID_MULTI>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@4 {
+ reg = <4>;
+ color = <LED_COLOR_ID_GREEN>;
+ };
+
+ led@5 {
+ reg = <5>;
+ color = <LED_COLOR_ID_AMBER>;
+ };
+ };
+
+ disk-4 {
+ function = LED_FUNCTION_DISK;
+ function-enumerator = <4>;
+ color = <LED_COLOR_ID_MULTI>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@6 {
+ reg = <6>;
+ color = <LED_COLOR_ID_GREEN>;
+ };
+
+ led@7 {
+ reg = <7>;
+ color = <LED_COLOR_ID_AMBER>;
+ };
+ };
+ };
+ };
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/4] rust: io: Add `RegisterArrayLoc::index`
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:21 ` 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:22 ` [PATCH v2 4/4] leds: Add driver for disk leds in synology devices Markus Probst
3 siblings, 1 reply; 12+ messages in thread
From: Markus Probst @ 2026-12-04 12:21 UTC (permalink / raw)
To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core,
Markus Probst
Add function to access index of `RegisterArrayLoc`.
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
rust/kernel/io/register.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index b6513fa0f412..c4f7be770dcb 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -192,6 +192,11 @@ pub fn try_new(idx: usize) -> Option<Self> {
None
}
}
+
+ /// Returns the array position.
+ pub const fn index(self) -> usize {
+ self.0
+ }
}
impl<Base: ?Sized, T> IoLoc<Base, T> for RegisterArrayLoc<T>
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/4] rust: io: Implement Copy for RegisterArrayLoc
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:21 ` [PATCH v2 2/4] rust: io: Add `RegisterArrayLoc::index` Markus Probst
@ 2026-12-04 12:21 ` Markus Probst
2026-12-04 12:33 ` sashiko-bot
2026-12-04 13:38 ` Gary Guo
2026-12-04 12:22 ` [PATCH v2 4/4] leds: Add driver for disk leds in synology devices Markus Probst
3 siblings, 2 replies; 12+ messages in thread
From: Markus Probst @ 2026-12-04 12:21 UTC (permalink / raw)
To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core,
Markus Probst
This allows storing `RegisterArrayLoc` and using it multiple times.
Derive is not possible, as it would introduce the unnecessary `T: Copy`
bound.
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
rust/kernel/io/register.rs | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index c4f7be770dcb..6381c52bd397 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -209,6 +209,14 @@ fn offset(self) -> usize {
}
}
+impl<T: RegisterArray> Copy for RegisterArrayLoc<T> {}
+
+impl<T: RegisterArray> Clone for RegisterArrayLoc<T> {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
/// Trait providing location builders for [`RegisterArray`]s.
pub trait Array {
/// Returns the location of the register at position `idx`, with build-time validation.
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/4] leds: Add driver for disk leds in synology devices
2026-12-04 12:21 [PATCH v2 0/4] leds: Add driver for disk leds in synology devices Markus Probst
` (2 preceding siblings ...)
2026-12-04 12:21 ` [PATCH v2 3/4] rust: io: Implement Copy for RegisterArrayLoc Markus Probst
@ 2026-12-04 12:22 ` Markus Probst
2026-12-04 13:32 ` sashiko-bot
3 siblings, 1 reply; 12+ messages in thread
From: Markus Probst @ 2026-12-04 12:22 UTC (permalink / raw)
To: Lee Jones, Pavel Machek, Griffin Kroah-Hartman, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda, Boqun Feng,
Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core,
Markus Probst
Synology uses an atmega1608 microcontroller as led controller for disk
leds via the I2C bus on its NAS devices. This adds the driver to control
those leds.
Successfully tested on a Synology DS923+.
Signed-off-by: Markus Probst <markus.probst@posteo.de>
---
MAINTAINERS | 7 +
drivers/leds/Kconfig | 9 +
drivers/leds/Makefile | 1 +
drivers/leds/leds_synology_disk.rs | 453 +++++++++++++++++++++++++++++++++++++
4 files changed, 470 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index d4fc9f48db34..ef1db5f95a37 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27144,6 +27144,13 @@ F: drivers/dma-buf/sync_*
F: include/linux/sync_file.h
F: include/uapi/linux/sync_file.h
+SYNOLOGY DISK LED CONTROLLER DRIVER
+M: Markus Probst <markus.probst@posteo.de>
+L: linux-leds@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/leds/synology,disk-leds.yaml
+F: drivers/leds/leds_synology_disk.rs
+
SYNOPSYS ARC ARCHITECTURE
M: Vineet Gupta <vgupta@kernel.org>
L: linux-snps-arc@lists.infradead.org
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 7ec2c8d78542..f8d543971847 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=y && LEDS_CLASS_MULTICOLOR=y
+ depends on I2C=y
+ depends on RUST
+ help
+ This option enables support for the led controller for disk leds in
+ synology devices.
+
config LEDS_COBALT_QUBE
tristate "LED Support for the Cobalt Qube series front LED"
depends on LEDS_CLASS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 4d4b089156e2..0c53186e819a 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -91,6 +91,7 @@ obj-$(CONFIG_LEDS_SC27XX_BLTC) += leds-sc27xx-bltc.o
obj-$(CONFIG_LEDS_ST1202) += leds-st1202.o
obj-$(CONFIG_LEDS_SUN50I_A100) += leds-sun50i-a100.o
obj-$(CONFIG_LEDS_SUNFIRE) += leds-sunfire.o
+obj-$(CONFIG_LEDS_SYNOLOGY_DISK) += leds_synology_disk.o
obj-$(CONFIG_LEDS_SYSCON) += leds-syscon.o
obj-$(CONFIG_LEDS_TCA6507) += leds-tca6507.o
obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o
diff --git a/drivers/leds/leds_synology_disk.rs b/drivers/leds/leds_synology_disk.rs
new file mode 100644
index 000000000000..6ae60bc89cac
--- /dev/null
+++ b/drivers/leds/leds_synology_disk.rs
@@ -0,0 +1,453 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Led Driver for Synology devices using Atmega1608 as Led Controller.
+//!
+//! Atmega1608 is a microcontroller from Microchip Technology, it is used
+//! as a led controller in synology nas devices for disk leds.
+//!
+//! It can handle a total of 24 leds. Each led has 4 modes:
+//! * OFF - the led is turned off
+//! * ON - the led is turned on at full brightness
+//! * DIM0 - custom brightness and optional hardware accelerated blinking
+//!
+//! there should also be DIM1 (which should do the same as DIM0), but
+//! according to my own testing it doesn't actually work, so it won't be used.
+//!
+//!
+//! # Limitations
+//!
+//! DIM0 (and DIM1) are shared across all leds, meaning if DIM0 is used by
+//! multiple leds, these multiple leds cannot have different brightness
+//! levels. The same does apply for the hardware accelerated blinking.
+//!
+//! In other words, for all 24 leds there can either only be one brightness other
+//! than 0 and 255, or one hardware accelerated blinking delay.
+//!
+//! Furthermore the off and on delay in hardware accelerated blinking cannot
+//! have different values and have to be equal.
+//!
+//! We solve this by only allowing a hardcoded blinking delay of 90 ms.
+//!
+//! While hardware accelerated blinking is on, the led cycles between
+//! the current brightness for the mode and full brightness. Because of this
+//! behaviour, we hardcode the brightness value of 128 for hardware accelerated
+//! blinking.
+//!
+//! Hardware accelerated blinking starts with a delay of 300 - 400 ms.
+//!
+//! # Technical details
+//!
+//! The controller has 6 8-bit i2c registers for led modes. See [`LedAddress`].
+//! Each led has its own 2 bits:
+//!
+//! +=====================================+
+//! | Register | Leds (2 bits each) |
+//! +=====================================+
+//! | 0x06 | LED3 LED2 LED1 LED0 |
+//! |-----------+-------------------------+
+//! | 0x07 | LED7 LED6 LED5 LED4 |
+//! |-----------+-------------------------+
+//! | 0x08 | LED11 LED10 LED9 LED8 |
+//! |-----------+-------------------------+
+//! | 0x09 | LED15 LED14 LED13 LED12 |
+//! |-----------+-------------------------+
+//! | 0x0A | LED19 LED18 LED17 LED16 |
+//! |-----------+-------------------------+
+//! | 0x0B | LED23 LED22 LED21 LED20 |
+//! |=====================================+
+//!
+//! See [`LedMode`] for the value of each mode.
+//!
+//!
+//! +===============================================+
+//! | Register | Mode / Meaning |
+//! +===============================================+
+//! | 0x01 | turns all leds off if set to 1 |
+//! +-----------------------------------------------+
+//! | 0x02 | blinking delay for Dim0, 1 = 3 ms |
+//! +-----------------------------------------------+
+//! | 0x03 | brightness for Dim0, inverted |
+//! +-----------------------------------------------+
+//! | 0x04 | blinking delay for Dim1, 1 = 3 ms |
+//! +-----------------------------------------------+
+//! | 0x05 | brightness for Dim1, inverted |
+//! +===============================================+
+//!
+
+use kernel::{
+ device::{
+ self,
+ Bound,
+ Core, //
+ },
+ i2c::{
+ self,
+ I2cClient,
+ I2cView, //
+ },
+ io::{
+ register::{
+ Array,
+ RegisterArray,
+ RegisterArrayLoc, //
+ },
+ Io,
+ IoLoc,
+ Region, //
+ },
+ led::{
+ self,
+ MultiColorDevice, //
+ },
+ new_mutex,
+ num::Bounded,
+ of,
+ prelude::*,
+ register,
+ sync::{
+ Arc,
+ Mutex, //
+ },
+};
+
+use zerocopy::{
+ try_transmute,
+ ValidityError, //
+};
+use zerocopy_derive::TryFromBytes;
+
+struct SynologyDiskLedDriver<'bound> {
+ client: &'bound I2cClient<Bound>,
+ _leds: KVec<Pin<KBox<MultiColorDevice<'bound, Led<'bound>>>>>,
+}
+
+kernel::module_i2c_driver! {
+ type: SynologyDiskLedDriver<'static>,
+ name: "leds_synology_disk",
+ authors: ["Markus Probst <markus.probst@posteo.de>"],
+ description: "Led Driver for disk leds in synology devices",
+ license: "GPL v2",
+}
+
+const LEDS_PER_ADDR: usize = 4;
+const LED_ADDRESSES: usize = 6;
+const LED_COUNT: usize = LED_ADDRESSES * LEDS_PER_ADDR;
+
+register! {
+ base: Region<256>;
+
+ MASK: bool @ 0x01;
+
+ DIM0_DELAY: u8 @ 0x02;
+ DIM0_BRIGHTNESS: u8 @ 0x03;
+ DIM1_DELAY: u8 @ 0x04;
+ DIM1_BRIGHTNESS: u8 @ 0x05;
+ Modes(u8)[LED_ADDRESSES] @ 0x06 {
+ 1:0 led1 ?=> LedMode;
+ 3:2 led2 ?=> LedMode;
+ 5:4 led3 ?=> LedMode;
+ 7:6 led4 ?=> LedMode;
+ }
+}
+
+#[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromBytes)]
+#[repr(u8)]
+enum LedMode {
+ Off = 0,
+ On = 1,
+ Dim0 = 2,
+ #[expect(dead_code)]
+ Dim1 = 3,
+}
+
+impl TryFrom<Bounded<u8, 2>> for LedMode {
+ type Error = ValidityError<u8, Self>;
+
+ fn try_from(value: Bounded<u8, 2>) -> Result<Self, Self::Error> {
+ try_transmute!(*value)
+ }
+}
+
+impl From<LedMode> for Bounded<u8, 2> {
+ fn from(value: LedMode) -> Self {
+ Self::from_expr(value as u8)
+ }
+}
+
+#[pin_data]
+struct LedAddressData {
+ addr: RegisterArrayLoc<Modes>,
+ #[pin]
+ data: Mutex<Modes>,
+}
+
+#[pin_data]
+struct Led<'bound> {
+ client: &'bound I2cClient<Bound>,
+ subleds: KVec<SubLed>,
+ #[pin]
+ blink: Mutex<bool>,
+}
+
+struct SubLed {
+ addr: Arc<LedAddressData>,
+ id: Bounded<u8, 2>,
+}
+
+kernel::of_device_table! {
+ OF_TABLE,
+ <SynologyDiskLedDriver<'_> as i2c::Driver>::IdInfo,
+ [(of::DeviceId::new(c"synology,disk-leds"), ())]
+}
+
+impl i2c::Driver for SynologyDiskLedDriver<'_> {
+ type IdInfo = ();
+ type Data<'bound> = SynologyDiskLedDriver<'bound>;
+
+ const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
+
+ fn probe<'bound>(
+ idev: &'bound I2cClient<Core<'_>>,
+ _id_info: Option<&'bound Self::IdInfo>,
+ ) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
+ let dev = idev.as_ref();
+
+ let fwnode = dev.fwnode().ok_or(EINVAL)?;
+
+ let io = idev.smbus_io();
+
+ let addrs = Self::init(&io, dev)?;
+
+ let mut used = [false; LED_COUNT];
+ let mut subleds_classdev = KVec::with_capacity(2, GFP_KERNEL)?;
+ let mut subleds;
+ let mut leds = KVec::new();
+
+ for child in fwnode.children() {
+ subleds_classdev.clear();
+ subleds = KVec::with_capacity(2, GFP_KERNEL)?;
+
+ for (index, color) in child.children().enumerate() {
+ let reg = usize::try_from(color.property_read::<u32>(c"reg").required_by(dev)?)?;
+ if reg >= LED_COUNT {
+ dev_err!(dev, "{}: property 'reg' is out of bounds\n", *color);
+ return Err(EINVAL);
+ }
+
+ if used[reg] {
+ dev_err!(
+ dev,
+ "{}: property 'reg' conflicts with a previous entry\n",
+ *color,
+ );
+ return Err(EINVAL);
+ }
+ used[reg] = true;
+
+ let color =
+ led::Color::try_from(color.property_read::<u32>(c"color").required_by(dev)?)
+ .map_err(|_err| {
+ dev_err!(dev, "{}: property 'color' is out of bounds\n", *color);
+ EINVAL
+ })?;
+ subleds_classdev.push(
+ led::MultiColorSubLed::builder(color)
+ .initial_intensity(if index == 0 { 1 } else { 0 })
+ .build(),
+ GFP_KERNEL,
+ )?;
+ subleds.push(
+ SubLed {
+ addr: Arc::clone(&addrs[reg / 4]),
+ id: Bounded::from_expr((reg % 4) as u8),
+ },
+ GFP_KERNEL,
+ )?;
+ }
+ debug_assert_eq!(subleds_classdev.len(), subleds.len());
+ if subleds_classdev.is_empty() {
+ dev_err!(dev, "{}: at least one subled is required\n", *child);
+ return Err(EINVAL);
+ }
+
+ leds.push(
+ KBox::pin_init(
+ led::DeviceBuilder::new()
+ .fwnode(Some(child))
+ .build_multicolor(
+ dev,
+ try_pin_init!(Led {
+ client: idev,
+ subleds,
+ blink <- new_mutex!(false),
+ }),
+ &subleds_classdev,
+ ),
+ GFP_KERNEL,
+ )?,
+ GFP_KERNEL,
+ )?;
+ }
+
+ io.try_write(MASK, false)
+ .inspect_err(|err| dev_err!(dev, "Unable to remove led mask: {err:?}\n"))?;
+
+ Ok(SynologyDiskLedDriver {
+ client: idev,
+ _leds: leds,
+ })
+ }
+}
+
+impl SynologyDiskLedDriver<'_> {
+ #[inline]
+ fn init(
+ io: &I2cView<'_, Region<256>>,
+ dev: &device::Device<Bound>,
+ ) -> Result<KVec<Arc<LedAddressData>>> {
+ io.try_write(DIM0_DELAY, 30)
+ .inspect_err(|err| dev_err!(dev, "Unable to set blink delay: {err:?}\n"))?;
+
+ io.try_write(DIM0_BRIGHTNESS, 127)
+ .inspect_err(|err| dev_err!(dev, "Unable to set blink brightness: {err:?}\n"))?;
+
+ let mut addrs = KVec::with_capacity(Modes::SIZE, GFP_KERNEL)?;
+ for index in 0..Modes::SIZE {
+ let addr = Modes::at(index);
+ io.try_write(addr, Modes::zeroed()).inspect_err(|err| {
+ dev_err!(
+ dev,
+ "Unable to reset leds at addr {:#2x}: {err:?}\n",
+ addr.offset()
+ )
+ })?;
+
+ addrs.push_within_capacity(Arc::pin_init(
+ try_pin_init!(LedAddressData {
+ addr,
+ data <- new_mutex!(Modes::zeroed()),
+ }),
+ GFP_KERNEL,
+ )?)?;
+ }
+ Ok(addrs)
+ }
+}
+
+impl Drop for SynologyDiskLedDriver<'_> {
+ fn drop(&mut self) {
+ let _ = self
+ .client
+ .smbus_io()
+ .try_write(MASK, true)
+ .inspect_err(|err| dev_err!(self.client.as_ref(), "Unable to set led mask: {err:?}\n"));
+ }
+}
+
+#[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(())
+ }
+}
+
+impl Led<'_> {
+ 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(())
+ }
+}
--
2.56.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 2/4] rust: io: Add `RegisterArrayLoc::index`
2026-12-04 12:21 ` [PATCH v2 2/4] rust: io: Add `RegisterArrayLoc::index` Markus Probst
@ 2026-12-04 12:30 ` sashiko-bot
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-12-04 12:30 UTC (permalink / raw)
To: Markus Probst; +Cc: linux-leds, devicetree, robh, conor+dt, lee, ojeda, gary
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] rust: io: missing #[inline] attribute on
RegisterArrayLoc::index()
- [Low] rust: io: commit message lacks motivation for
RegisterArrayLoc::index()
--
commit 24b30809d05fdd14bb53e8158bd023ab029e6ae1
Author: Markus Probst <markus.probst@posteo.de>
> rust: io: Add `RegisterArrayLoc::index`
>
> Add function to access index of `RegisterArrayLoc`.
>
> Signed-off-by: Markus Probst <markus.probst@posteo.de>
[Severity: Low]
Could the commit message briefly explain why RegisterArrayLoc::index() is
being added? Right now the body only restates the subject, and since this
introduces a new public method with no callers in this patch, some context
on the intended use case would help reviewers.
> diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
> index b6513fa0f412c..c4f7be770dcb8 100644
> --- a/rust/kernel/io/register.rs
> +++ b/rust/kernel/io/register.rs
> @@ -192,6 +192,11 @@ pub fn try_new(idx: usize) -> Option<Self> {
> None
> }
> }
> +
> + /// Returns the array position.
> + pub const fn index(self) -> usize {
> + self.0
> + }
> }
[Severity: Low]
Should RegisterArrayLoc::index() be marked #[inline]? Small functions in
kernel abstractions are expected to carry #[inline], matching sibling
accessors like OffsetLoc::const_offset() in the same file.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-synology_disk_leds-v2-0-12815785ff8b@posteo.de?part=2
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] rust: io: Implement Copy for RegisterArrayLoc
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
1 sibling, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-12-04 12:33 UTC (permalink / raw)
To: Markus Probst; +Cc: linux-leds, devicetree, robh, conor+dt, lee, ojeda, gary
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] rust: io: missing #[inline] on RegisterArrayLoc::clone()
--
commit 0349592296d0ffae8398cc3d95e7f43776ae3bee
Author: Markus Probst <markus.probst@posteo.de>
rust: io: Implement Copy for RegisterArrayLoc
This commit manually implements Copy and Clone for RegisterArrayLoc<T>
without requiring a T: Copy bound.
> diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
> index c4f7be770dcb8..6381c52bd397a 100644
> --- a/rust/kernel/io/register.rs
> +++ b/rust/kernel/io/register.rs
> @@ -209,6 +209,14 @@ fn offset(self) -> usize {
> }
> }
>
> +impl<T: RegisterArray> Copy for RegisterArrayLoc<T> {}
> +
> +impl<T: RegisterArray> Clone for RegisterArrayLoc<T> {
> + fn clone(&self) -> Self {
> + *self
> + }
> +}
[Severity: Low]
Should RegisterArrayLoc::clone() be marked #[inline]? Small functions in the
kernel crate are expected to carry #[inline] so they can be inlined across
crate boundaries, matching other manual Clone implementations in kernel::io
such as MmioRaw::clone().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-synology_disk_leds-v2-0-12815785ff8b@posteo.de?part=3
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/4] dt-bindings: leds: Add synology disk led controller
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
0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-12-04 12:35 UTC (permalink / raw)
To: Markus Probst; +Cc: linux-leds, devicetree, robh, conor+dt, lee, ojeda, gary
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] dt-bindings: leds: disk-[0-9]+ pattern conflicts with
multicolor schema
- [Low] dt-bindings: leds: sub-LED schema redefines color instead of
common.yaml
- [Low] dt-bindings: leds: compatible string synology,disk-leds is
overly generic
--
commit 8267366bd846e6cdfc61f3502ed024437f23e40c
Author: Markus Probst <markus.probst@posteo.de>
dt-bindings: leds: Add synology disk led controller
This commit adds a Devicetree binding schema for the Synology ATmega1608
I2C disk LED controller.
> diff --git a/Documentation/devicetree/bindings/leds/synology,disk-leds.yaml b/Documentation/devicetree/bindings/leds/synology,disk-leds.yaml
> new file mode 100644
> index 0000000000000..2c2e1e35c265b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/leds/synology,disk-leds.yaml
> @@ -0,0 +1,151 @@
[ ... ]
> +properties:
> + compatible:
> + const: synology,disk-leds
[Severity: Low]
Is synology,disk-leds too generic for a compatible string?
Other Synology models already use different disk LED hardware, so an
unqualified compatible risks ABI collisions across hardware generations
or ATmega1608 firmware variants. Should this identify a specific model
or controller implementation (like cznic,turris-omnia-leds)?
> +
> + reg:
> + maxItems: 1
> +
> +patternProperties:
> + "^disk-[0-9]+$":
> + type: object
> + $ref: leds-class-multicolor.yaml#
> + unevaluatedProperties: false
[Severity: Medium]
Does the "^disk-[0-9]+$" node name pattern conflict with
leds-class-multicolor.yaml#?
leds-class-multicolor.yaml# requires $nodename to match
"^multi-led(@[0-9a-f]|-[0-9]+)?$". Because the two patterns are
disjoint and the controller sets additionalProperties: false, make
dt_binding_check fails on the examples and no DTS node can validate.
Renaming the pattern and example nodes to match "^multi-led-[0-9]+$"
would satisfy the multicolor schema, since function and
function-enumerator already identify the disk slot.
[ ... ]
> + patternProperties:
> + "^led@[0-9a-f]+$":
> + type: object
> + additionalProperties: false
> +
> + properties:
> + reg:
> + description: Index of the LED.
> + minimum: 0
> + maximum: 23
> +
> + color:
> + description: Color of the LED.
> + $ref: /schemas/types.yaml#/definitions/uint32
> + minimum: 0
> + maximum: 14
[Severity: Low]
Can "^led@[0-9a-f]+$" reference common.yaml# with unevaluatedProperties:
false instead of redefining color inline?
Hardcoding color with maximum: 14 duplicates common.yaml and will drift
when new LED_COLOR_ID_* values are added. Setting additionalProperties:
false also prevents boards from specifying standard multicolor sub-LED
properties from common.yaml such as default-intensity.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-synology_disk_leds-v2-0-12815785ff8b@posteo.de?part=1
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] leds: Add driver for disk leds in synology devices
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
0 siblings, 1 reply; 12+ messages in thread
From: sashiko-bot @ 2026-12-04 13:32 UTC (permalink / raw)
To: Markus Probst; +Cc: linux-leds, devicetree, robh, conor+dt, lee, ojeda, gary
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?
[ ... ]
> + 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.
[ ... ]
> + 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.
[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.
[ ... ]
> + 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-synology_disk_leds-v2-0-12815785ff8b@posteo.de?part=4
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] rust: io: Implement Copy for RegisterArrayLoc
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
1 sibling, 1 reply; 12+ messages in thread
From: Gary Guo @ 2026-12-04 13:38 UTC (permalink / raw)
To: Markus Probst, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core
On Fri Dec 4, 2026 at 12:21 PM GMT, Markus Probst wrote:
> This allows storing `RegisterArrayLoc` and using it multiple times.
>
> Derive is not possible, as it would introduce the unnecessary `T: Copy`
> bound.
>
> Signed-off-by: Markus Probst <markus.probst@posteo.de>
It's already in linux-next but I think it's via drm-rust-next tree.
Best,
Gary
> ---
> rust/kernel/io/register.rs | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
> index c4f7be770dcb..6381c52bd397 100644
> --- a/rust/kernel/io/register.rs
> +++ b/rust/kernel/io/register.rs
> @@ -209,6 +209,14 @@ fn offset(self) -> usize {
> }
> }
>
> +impl<T: RegisterArray> Copy for RegisterArrayLoc<T> {}
> +
> +impl<T: RegisterArray> Clone for RegisterArrayLoc<T> {
> + fn clone(&self) -> Self {
> + *self
> + }
> +}
> +
> /// Trait providing location builders for [`RegisterArray`]s.
> pub trait Array {
> /// Returns the location of the register at position `idx`, with build-time validation.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 3/4] rust: io: Implement Copy for RegisterArrayLoc
2026-12-04 13:38 ` Gary Guo
@ 2026-12-04 13:42 ` Markus Probst
0 siblings, 0 replies; 12+ messages in thread
From: Markus Probst @ 2026-12-04 13:42 UTC (permalink / raw)
To: Gary Guo, Lee Jones, Pavel Machek, Griffin Kroah-Hartman,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Miguel Ojeda,
Boqun Feng, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Alice Ryhl, Trevor Gross, Danilo Krummrich, Daniel Almeida,
Tamir Duberstein, Alexandre Courbot, Onur Özkan
Cc: linux-leds, devicetree, linux-kernel, rust-for-linux, driver-core
[-- Attachment #1: Type: text/plain, Size: 515 bytes --]
On Fri, 2026-12-04 at 13:38 +0000, Gary Guo wrote:
> On Fri Dec 4, 2026 at 12:21 PM GMT, Markus Probst wrote:
> > This allows storing `RegisterArrayLoc` and using it multiple times.
> >
> > Derive is not possible, as it would introduce the unnecessary `T: Copy`
> > bound.
> >
> > Signed-off-by: Markus Probst <markus.probst@posteo.de>
>
> It's already in linux-next but I think it's via drm-rust-next tree.
>
> Best,
> Gary
Thanks for the info.
I will drop the patch.
Thanks
- Markus Probst
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 870 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 4/4] leds: Add driver for disk leds in synology devices
2026-12-04 13:32 ` sashiko-bot
@ 2026-12-04 16:54 ` Markus Probst
0 siblings, 0 replies; 12+ messages in thread
From: Markus Probst @ 2026-12-04 16:54 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-leds, devicetree, robh, conor+dt, lee, ojeda, gary
[-- 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 --]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-04 16:54 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox