Commit eb6e2924 authored by Petr Mladek's avatar Petr Mladek Committed by Greg Kroah-Hartman

usb: hub: rename hub_events() to hub_event() and handle only one event there

We would like to convert khubd kthread to a workqueue. As a result hub_events()
will handle only one event per call.

In fact, we could do this already now because there is another cycle in
hub_thread(). It calls hub_events() until hub_event_list is empty.

This patch renames the function to hub_event(), removes the while cycle, and
renames the goto targets from loop* to out*.

When touching the code, it fixes also formatting of dev_err() and dev_dbg()
calls to make checkpatch.pl happy :-)
Signed-off-by: default avatarPetr Mladek <pmladek@suse.cz>
Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5d14f323
...@@ -4996,8 +4996,7 @@ static void port_event(struct usb_hub *hub, int port1) ...@@ -4996,8 +4996,7 @@ static void port_event(struct usb_hub *hub, int port1)
hub_port_connect_change(hub, port1, portstatus, portchange); hub_port_connect_change(hub, port1, portstatus, portchange);
} }
static void hub_event(void)
static void hub_events(void)
{ {
struct list_head *tmp; struct list_head *tmp;
struct usb_device *hdev; struct usb_device *hdev;
...@@ -5008,19 +5007,11 @@ static void hub_events(void) ...@@ -5008,19 +5007,11 @@ static void hub_events(void)
u16 hubchange; u16 hubchange;
int i, ret; int i, ret;
/*
* We restart the list every time to avoid a deadlock with
* deleting hubs downstream from this one. This should be
* safe since we delete the hub from the event list.
* Not the most efficient, but avoids deadlocks.
*/
while (1) {
/* Grab the first entry at the beginning of the list */ /* Grab the first entry at the beginning of the list */
spin_lock_irq(&hub_event_lock); spin_lock_irq(&hub_event_lock);
if (list_empty(&hub_event_list)) { if (list_empty(&hub_event_list)) {
spin_unlock_irq(&hub_event_lock); spin_unlock_irq(&hub_event_lock);
break; return;
} }
tmp = hub_event_list.next; tmp = hub_event_list.next;
...@@ -5043,35 +5034,33 @@ static void hub_events(void) ...@@ -5043,35 +5034,33 @@ static void hub_events(void)
* disconnected while waiting for the lock to succeed. */ * disconnected while waiting for the lock to succeed. */
usb_lock_device(hdev); usb_lock_device(hdev);
if (unlikely(hub->disconnected)) if (unlikely(hub->disconnected))
goto loop_disconnected; goto out_disconnected;
/* If the hub has died, clean up after it */ /* If the hub has died, clean up after it */
if (hdev->state == USB_STATE_NOTATTACHED) { if (hdev->state == USB_STATE_NOTATTACHED) {
hub->error = -ENODEV; hub->error = -ENODEV;
hub_quiesce(hub, HUB_DISCONNECT); hub_quiesce(hub, HUB_DISCONNECT);
goto loop; goto out;
} }
/* Autoresume */ /* Autoresume */
ret = usb_autopm_get_interface(intf); ret = usb_autopm_get_interface(intf);
if (ret) { if (ret) {
dev_dbg(hub_dev, "Can't autoresume: %d\n", ret); dev_dbg(hub_dev, "Can't autoresume: %d\n", ret);
goto loop; goto out;
} }
/* If this is an inactive hub, do nothing */ /* If this is an inactive hub, do nothing */
if (hub->quiescing) if (hub->quiescing)
goto loop_autopm; goto out_autopm;
if (hub->error) { if (hub->error) {
dev_dbg (hub_dev, "resetting for error %d\n", dev_dbg(hub_dev, "resetting for error %d\n", hub->error);
hub->error);
ret = usb_reset_device(hdev); ret = usb_reset_device(hdev);
if (ret) { if (ret) {
dev_dbg (hub_dev, dev_dbg(hub_dev, "error resetting hub: %d\n", ret);
"error resetting hub: %d\n", ret); goto out_autopm;
goto loop_autopm;
} }
hub->nerrors = 0; hub->nerrors = 0;
...@@ -5107,10 +5096,10 @@ static void hub_events(void) ...@@ -5107,10 +5096,10 @@ static void hub_events(void)
if (test_and_clear_bit(0, hub->event_bits) == 0) if (test_and_clear_bit(0, hub->event_bits) == 0)
; /* do nothing */ ; /* do nothing */
else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0) else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0)
dev_err (hub_dev, "get_hub_status failed\n"); dev_err(hub_dev, "get_hub_status failed\n");
else { else {
if (hubchange & HUB_CHANGE_LOCAL_POWER) { if (hubchange & HUB_CHANGE_LOCAL_POWER) {
dev_dbg (hub_dev, "power change\n"); dev_dbg(hub_dev, "power change\n");
clear_hub_feature(hdev, C_HUB_LOCAL_POWER); clear_hub_feature(hdev, C_HUB_LOCAL_POWER);
if (hubstatus & HUB_STATUS_LOCAL_POWER) if (hubstatus & HUB_STATUS_LOCAL_POWER)
/* FIXME: Is this always true? */ /* FIXME: Is this always true? */
...@@ -5128,24 +5117,21 @@ static void hub_events(void) ...@@ -5128,24 +5117,21 @@ static void hub_events(void)
hub_power_on(hub, true); hub_power_on(hub, true);
hub_hub_status(hub, &status, &unused); hub_hub_status(hub, &status, &unused);
if (status & HUB_STATUS_OVERCURRENT) if (status & HUB_STATUS_OVERCURRENT)
dev_err(hub_dev, "over-current " dev_err(hub_dev, "over-current condition\n");
"condition\n");
} }
} }
loop_autopm: out_autopm:
/* Balance the usb_autopm_get_interface() above */ /* Balance the usb_autopm_get_interface() above */
usb_autopm_put_interface_no_suspend(intf); usb_autopm_put_interface_no_suspend(intf);
loop: out:
/* Balance the usb_autopm_get_interface_no_resume() in /* Balance the usb_autopm_get_interface_no_resume() in
* kick_khubd() and allow autosuspend. * kick_khubd() and allow autosuspend.
*/ */
usb_autopm_put_interface(intf); usb_autopm_put_interface(intf);
loop_disconnected: out_disconnected:
usb_unlock_device(hdev); usb_unlock_device(hdev);
kref_put(&hub->kref, hub_release); kref_put(&hub->kref, hub_release);
} /* end while (1) */
} }
static int hub_thread(void *__unused) static int hub_thread(void *__unused)
...@@ -5158,7 +5144,7 @@ static int hub_thread(void *__unused) ...@@ -5158,7 +5144,7 @@ static int hub_thread(void *__unused)
set_freezable(); set_freezable();
do { do {
hub_events(); hub_event();
wait_event_freezable(khubd_wait, wait_event_freezable(khubd_wait,
!list_empty(&hub_event_list) || !list_empty(&hub_event_list) ||
kthread_should_stop()); kthread_should_stop());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment