aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/hack-4.19/160-leds-fix-regression-in-usbport-led-trigger.patch
blob: e24cac3ddd242c62c835e214348cfdfcbea1c27a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 38a3549ffc0033761063cc5c7b994ab075694db8 Mon Sep 17 00:00:00 2001
From: Christian Lamparter <chunkeey@gmail.com>
Date: Tue, 25 Dec 2018 21:11:08 +0100
Subject: [RFC PATCH] leds: fix regression in usbport led trigger

In the patch "usb: simplify usbport trigger" together with
"leds: triggers: add device attribute support" caused an
regression for the usbport trigger. it will no longer
enumerate any "ports" (i.e the sysfs directory stays empty)
if the usb host drivers are fully initialized before the
usbport trigger was loaded.

The reason is that the usbport driver registers the sysfs
entries in the ports subdirectory during the activate()
callback. Whereas the patch
"leds: triggers: add device attribute support" made it so
that the sysfs "ports" group was only being added after
the activate() callback succeeded.

This patch moves the device_add_groups() in front of the
call to the trigger's activate() function in order to
solve the problem.

Fixes: 6f7b0bad8839 ("usb: simplify usbport trigger")
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
---
 drivers/leds/led-triggers.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -134,6 +134,12 @@ int led_trigger_set(struct led_classdev
 		led_set_brightness(led_cdev, LED_OFF);
 	}
 	if (trig) {
+		ret = device_add_groups(led_cdev->dev, trig->groups);
+		if (ret) {
+			dev_err(led_cdev->dev, "Failed to add trigger attributes\n");
+			goto err_add_groups;
+		}
+
 		write_lock_irqsave(&trig->leddev_list_lock, flags);
 		list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
 		write_unlock_irqrestore(&trig->leddev_list_lock, flags);
@@ -146,12 +152,6 @@ int led_trigger_set(struct led_classdev
 
 		if (ret)
 			goto err_activate;
-
-		ret = device_add_groups(led_cdev->dev, trig->groups);
-		if (ret) {
-			dev_err(led_cdev->dev, "Failed to add trigger attributes\n");
-			goto err_add_groups;
-		}
 	}
 
 	if (event) {
@@ -165,17 +165,18 @@ int led_trigger_set(struct led_classdev
 
 	return 0;
 
-err_add_groups:
-
+err_activate:
+	device_remove_groups(led_cdev->dev, trig->groups);
 	if (trig->deactivate)
 		trig->deactivate(led_cdev);
-err_activate:
 
 	led_cdev->trigger = NULL;
 	led_cdev->trigger_data = NULL;
 	write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags);
 	list_del(&led_cdev->trig_list);
 	write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
+
+err_add_groups:
 	led_set_brightness(led_cdev, LED_OFF);
 
 	return ret;