Skip to content

Commit

Permalink
USB: leds: fix regression in usbport led trigger
Browse files Browse the repository at this point in the history
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 active usb hub ports under the
"ports" directory in the sysfs class directory, if the usb host drivers
are fully initialized before the usbport trigger was loaded.

The reason is that the usbport driver tries to register the sysfs
entries during the activate() callback. And this will fail with -2 /
ENOENT because 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 version of the patch reverts parts of the "usb: simplify usbport
trigger" patch and restores usbport trigger's functionality.

Fixes: 6f7b0ba ("usb: simplify usbport trigger")
Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Cc: stable <stable@vger.kernel.org>
Acked-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Christian Lamparter authored and Greg Kroah-Hartman committed Jan 18, 2019
1 parent 8ff396f commit 91f7d2e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions drivers/usb/core/ledtrig-usbport.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ static const struct attribute_group ports_group = {
.attrs = ports_attrs,
};

static const struct attribute_group *ports_groups[] = {
&ports_group,
NULL
};

/***************************************
* Adding & removing ports
***************************************/
Expand Down Expand Up @@ -307,6 +302,7 @@ static int usbport_trig_notify(struct notifier_block *nb, unsigned long action,
static int usbport_trig_activate(struct led_classdev *led_cdev)
{
struct usbport_trig_data *usbport_data;
int err;

usbport_data = kzalloc(sizeof(*usbport_data), GFP_KERNEL);
if (!usbport_data)
Expand All @@ -315,15 +311,21 @@ static int usbport_trig_activate(struct led_classdev *led_cdev)

/* List of ports */
INIT_LIST_HEAD(&usbport_data->ports);
err = sysfs_create_group(&led_cdev->dev->kobj, &ports_group);
if (err)
goto err_free;
usb_for_each_dev(usbport_data, usbport_trig_add_usb_dev_ports);
usbport_trig_update_count(usbport_data);

/* Notifications */
usbport_data->nb.notifier_call = usbport_trig_notify;
led_set_trigger_data(led_cdev, usbport_data);
usb_register_notify(&usbport_data->nb);

return 0;

err_free:
kfree(usbport_data);
return err;
}

static void usbport_trig_deactivate(struct led_classdev *led_cdev)
Expand All @@ -335,6 +337,8 @@ static void usbport_trig_deactivate(struct led_classdev *led_cdev)
usbport_trig_remove_port(usbport_data, port);
}

sysfs_remove_group(&led_cdev->dev->kobj, &ports_group);

usb_unregister_notify(&usbport_data->nb);

kfree(usbport_data);
Expand All @@ -344,7 +348,6 @@ static struct led_trigger usbport_led_trigger = {
.name = "usbport",
.activate = usbport_trig_activate,
.deactivate = usbport_trig_deactivate,
.groups = ports_groups,
};

static int __init usbport_trig_init(void)
Expand Down

0 comments on commit 91f7d2e

Please sign in to comment.