[PATCH v2 0/4] leds: trigger: netdev: fix sysfs_update_group() races
From: A. Sverdlin
Date: Mon Sep 21 2026 - 05:44:07 EST
From: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
The netdev LED trigger refreshes the link_speed attribute group with
sysfs_update_group() from several contexts (the NETDEV_CHANGE notifier,
device_name writes and, indirectly, trigger (de)activation) that share no
common lock. On a board that emits PHY link events while the trigger is
being (re)armed during boot this is observed as a hard sysfs failure:
sysfs: cannot create duplicate filename '...green:lan/link_10'
...
led_trigger_set
led_trigger_write
The window between activate() and device_add_groups() in led_trigger_set()
is narrow, so to reproduce it reliably I artificially widened it with the
debug patch below:
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -12,6 +12,7 @@
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/device.h>
+#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/rwsem.h>
#include <linux/leds.h>
@@ -223,6 +224,8 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
if (ret)
goto err_activate;
+ msleep(5000);
+
ret = device_add_groups(led_cdev->dev, trig->groups);
if (ret) {
dev_err(led_cdev->dev, "Failed to add trigger attributes\n");
With that msleep() in place, writing the trigger while a NETDEV_CHANGE is
delivered from the linkwatch workqueue reproduces the duplicate-filename
splat every time.
The whole series is LOCKDEP-verified.
Changelog:
v2:
- addressed pre-existing issues found by Sashiko (patches 1&2)
- reduced verbosity both in comments and in commit messages
- patch 3 is a combined rework of patches 1&2 from v1
- dropped sync from cancel_delayed_work() (worker now takes the lock)
v1:
https://lore.kernel.org/all/20260914132356.807004-1-alexander.sverdlin@xxxxxxxxxxx/
Alexander Sverdlin (4):
leds: trigger: netdev: Put netdev on activate error path
leds: trigger: netdev: Access net_dev under trigger_data->lock in the
worker
leds: trigger: netdev: Fix sysfs_update_group() races
leds: trigger: netdev: Serialize mode/interval stores with trigger
lock
drivers/leds/trigger/ledtrig-netdev.c | 54 +++++++++++++++++++++------
1 file changed, 43 insertions(+), 11 deletions(-)
--
2.55.0