Thread (19 messages) flat view 19 messages, 2 authors, 11h ago

Re: [PATCH v7 08/13] leds: trigger: netdev: Implement hw_offloaded() callback

From: Rong Zhang <hidden>
Date: 2026-09-24 11:50:45
Also in: chrome-platform, linux-doc, linux-leds, lkml, platform-driver-x86

Hi Lee,

Thanks for your review.

On Thu, 2026-09-24 at 09:53 +0100, Lee Jones wrote:
quoted hunk ↗ jump to hunk
--- checkpatch.pl: clean (0 issues) ---
On Mon, 21 Sep 2026, Rong Zhang wrote:
quoted
"netdev" can run in hardware control according to hardware capabilities
and trigger options.

Implement hw_offloaded() callback to provide its hardware control state
to the LED core, and document the relation between the custom
"offloaded" attribute and the generic "trigger_may_offload_to_hw"
attribute.

The callback mimics how the existing "offloaded" attribute does, i.e.,
locklessly reads hw_control, as it's just a hint and don't need to be
accurate.

Acked-by: Ike Panhc <ikepanhc@gmail.com>
Signed-off-by: Rong Zhang <redacted>
---
Changes in v7:
- Rename the offloaded() callback to hw_offloaded() (thanks Lee Jones)
- Rename the trigger_may_offload attribute to
  trigger_may_offload_to_hw (ditto)

Changes in v3:
- Do not deprecate netdev's "offloaded" attribute (thanks Thomas
  Weißschuh)
- Document the relation between the custom "offloaded" attribute and the
  generic "trigger_may_offload" attribute (ditto)
---
 Documentation/ABI/testing/sysfs-class-led                | 3 +++
 Documentation/ABI/testing/sysfs-class-led-trigger-netdev | 3 +++
 drivers/leds/trigger/ledtrig-netdev.c                    | 8 ++++++++
 3 files changed, 14 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-led b/Documentation/ABI/testing/sysfs-class-led
index 123e3a15b7d6..ea113fed10ef 100644
--- a/Documentation/ABI/testing/sysfs-class-led
+++ b/Documentation/ABI/testing/sysfs-class-led
@@ -101,6 +101,9 @@ Description:
 		- `[foo_trigger]`: the trigger is selected and offloaded to
 		  hardware.
 
+		The "netdev" trigger also provides a custom attribute to
+		indicate its state, see `/sys/class/leds/<led>/offloaded`.
+
 What:		/sys/class/leds/<led>/inverted
 Date:		January 2011
 KernelVersion:	2.6.38
diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
index ed46b37ab8a2..203ea58396ed 100644
--- a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
+++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev
@@ -75,6 +75,9 @@ Description:
 		If 1, the LED blinking in requested mode is offloaded to
 		hardware.
 
+		LED trigger core also provides a generic attribute for this
+		purpose, see `/sys/class/leds/<led>/trigger_may_offload_to_hw`.
+
 What:		/sys/class/leds/<led>/link_10
 Date:		Jun 2023
 KernelVersion:	6.5
diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 5b4e92c14dbb..60409f054e22 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -798,10 +798,18 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev)
 	kfree(trigger_data);
 }
 
+static bool netdev_trig_hw_offloaded(struct led_classdev *led_cdev)
+{
+	struct led_netdev_data *trigger_data = led_get_trigger_data(led_cdev);
+
+	return trigger_data->hw_control;
How sure are we that trigger_data can NEVER be NULL?
The hw_offloaded() callback is protected by led_cdev->trigger_lock, see
__led_trigger_is_hw_controlled().

trigger_data is set in the trigger's activate() callback, which is
protected by led_cdev->trigger_lock.

trigger_data is cleared in led_trigger_set() when removing the current
trigger, which is, again, protected by led_cdev->trigger_lock.

When CONFIG_LEDS_TRIGGERS=n, the code is not built.

If the trigger is currently inactive, the callback cannot be called.

Therefore, it can never be NULL when we reach here.

Note that the trigger's DEVICE_ATTR_RO(offloaded) makes the same
assumption, too.

Thanks,
Rong
quoted
+}
+
 static struct led_trigger netdev_led_trigger = {
 	.name = "netdev",
 	.activate = netdev_trig_activate,
 	.deactivate = netdev_trig_deactivate,
+	.hw_offloaded = netdev_trig_hw_offloaded,
 	.groups = netdev_trig_groups,
 };
 

-- 
2.55.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help