diff mbox series

[v4] leds: trigger: netdev: skip setting baseline state in activate if hw-controlled

Message ID d3f2859c-2673-401c-a4f7-fcaef2167991@gmail.com
State Superseded
Headers show
Series [v4] leds: trigger: netdev: skip setting baseline state in activate if hw-controlled | expand

Commit Message

Heiner Kallweit Dec. 21, 2023, 5:31 p.m. UTC
The current codes uses the sw_control path in set_baseline_state() when
called from netdev_trig_activate() even if we're hw-controlled. This
may result in errors when led_set_brightness() is called because we may
not have set_brightness led ops (if hw doesn't support setting a "LED"
to ON). In addition this path may schedule trigger_data->work which
doesn't make sense when being hw-controlled.

Therefore set trigger_data->hw_control = true before calling
set_device_name() from netdev_trig_activate(). In this call chain we
have to prevent set_baseline_state() from being called, because this
would call hw_control_set(). Use led_cdev->trigger_data == NULL as
indicator for being called from netdev_trig_activate().

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v2:
- improve commit message
v3:
- spelling and style fixes
v4:
- rebased on top of for-leds-next
---
 drivers/leds/trigger/ledtrig-netdev.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Lee Jones Jan. 11, 2024, 9:10 a.m. UTC | #1
On Thu, 21 Dec 2023 18:31:48 +0100, Heiner Kallweit wrote:
> The current codes uses the sw_control path in set_baseline_state() when
> called from netdev_trig_activate() even if we're hw-controlled. This
> may result in errors when led_set_brightness() is called because we may
> not have set_brightness led ops (if hw doesn't support setting a "LED"
> to ON). In addition this path may schedule trigger_data->work which
> doesn't make sense when being hw-controlled.
> 
> [...]

Applied, thanks!

[1/1] leds: trigger: netdev: skip setting baseline state in activate if hw-controlled
      commit: 5df2b4ed10a4ea636bb5ace99712a7d0c6226a55

--
Lee Jones [李琼斯]
diff mbox series

Patch

diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c
index 836610292..192662e05 100644
--- a/drivers/leds/trigger/ledtrig-netdev.c
+++ b/drivers/leds/trigger/ledtrig-netdev.c
@@ -275,7 +275,10 @@  static int set_device_name(struct led_netdev_data *trigger_data,
 
 	trigger_data->last_activity = 0;
 
-	set_baseline_state(trigger_data);
+	/* Skip if we're called from netdev_trig_activate() and hw_control is true */
+	if (!trigger_data->hw_control || led_get_trigger_data(trigger_data->led_cdev))
+		set_baseline_state(trigger_data);
+
 	mutex_unlock(&trigger_data->lock);
 
 	return 0;
@@ -614,8 +617,8 @@  static int netdev_trig_activate(struct led_classdev *led_cdev)
 		if (dev) {
 			const char *name = dev_name(dev);
 
-			set_device_name(trigger_data, name, strlen(name));
 			trigger_data->hw_control = true;
+			set_device_name(trigger_data, name, strlen(name));
 
 			rc = led_cdev->hw_control_get(led_cdev, &mode);
 			if (!rc)