kernel: bump 4.14 to 4.14.97
[openwrt/openwrt.git] / target / linux / generic / backport-4.19 / 800-v5.0-usb-leds-fix-regression-in-usbport-led-trigger.patch
1 From 91f7d2e89868fcac0e750a28230fdb1ad4512137 Mon Sep 17 00:00:00 2001
2 From: Christian Lamparter <chunkeey@gmail.com>
3 Date: Fri, 11 Jan 2019 17:29:45 +0100
4 Subject: USB: leds: fix regression in usbport led trigger
5
6 The patch "usb: simplify usbport trigger" together with "leds: triggers:
7 add device attribute support" caused an regression for the usbport
8 trigger. it will no longer enumerate any active usb hub ports under the
9 "ports" directory in the sysfs class directory, if the usb host drivers
10 are fully initialized before the usbport trigger was loaded.
11
12 The reason is that the usbport driver tries to register the sysfs
13 entries during the activate() callback. And this will fail with -2 /
14 ENOENT because the patch "leds: triggers: add device attribute support"
15 made it so that the sysfs "ports" group was only being added after the
16 activate() callback succeeded.
17
18 This version of the patch reverts parts of the "usb: simplify usbport
19 trigger" patch and restores usbport trigger's functionality.
20
21 Fixes: 6f7b0bad8839 ("usb: simplify usbport trigger")
22 Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
23 Cc: stable <stable@vger.kernel.org>
24 Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
25 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 ---
27 --- a/drivers/usb/core/ledtrig-usbport.c
28 +++ b/drivers/usb/core/ledtrig-usbport.c
29 @@ -119,11 +119,6 @@ static const struct attribute_group port
30 .attrs = ports_attrs,
31 };
32
33 -static const struct attribute_group *ports_groups[] = {
34 - &ports_group,
35 - NULL
36 -};
37 -
38 /***************************************
39 * Adding & removing ports
40 ***************************************/
41 @@ -307,6 +302,7 @@ static int usbport_trig_notify(struct no
42 static int usbport_trig_activate(struct led_classdev *led_cdev)
43 {
44 struct usbport_trig_data *usbport_data;
45 + int err;
46
47 usbport_data = kzalloc(sizeof(*usbport_data), GFP_KERNEL);
48 if (!usbport_data)
49 @@ -315,6 +311,9 @@ static int usbport_trig_activate(struct
50
51 /* List of ports */
52 INIT_LIST_HEAD(&usbport_data->ports);
53 + err = sysfs_create_group(&led_cdev->dev->kobj, &ports_group);
54 + if (err)
55 + goto err_free;
56 usb_for_each_dev(usbport_data, usbport_trig_add_usb_dev_ports);
57 usbport_trig_update_count(usbport_data);
58
59 @@ -322,8 +321,11 @@ static int usbport_trig_activate(struct
60 usbport_data->nb.notifier_call = usbport_trig_notify;
61 led_set_trigger_data(led_cdev, usbport_data);
62 usb_register_notify(&usbport_data->nb);
63 -
64 return 0;
65 +
66 +err_free:
67 + kfree(usbport_data);
68 + return err;
69 }
70
71 static void usbport_trig_deactivate(struct led_classdev *led_cdev)
72 @@ -335,6 +337,8 @@ static void usbport_trig_deactivate(stru
73 usbport_trig_remove_port(usbport_data, port);
74 }
75
76 + sysfs_remove_group(&led_cdev->dev->kobj, &ports_group);
77 +
78 usb_unregister_notify(&usbport_data->nb);
79
80 kfree(usbport_data);
81 @@ -344,7 +348,6 @@ static struct led_trigger usbport_led_tr
82 .name = "usbport",
83 .activate = usbport_trig_activate,
84 .deactivate = usbport_trig_deactivate,
85 - .groups = ports_groups,
86 };
87
88 static int __init usbport_trig_init(void)