800-v5.0-usb-leds-fix-regression-in-usbport-led-trigger.patch 3.0 KB

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