Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: reorganize code in hub.c

This patch (as1045) reorganizes some code in the hub driver.
hub_port_status() is moved earlier in the file, and a new hub_stop()
routine is created to do the work currently in hub_preset() (i.e.,
disconnect all child devices and quiesce the hub).

There are no functional changes.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
3eb14915 3bb1af52

+32 -26
+32 -26
drivers/usb/core/hub.c
··· 333 333 return status; 334 334 } 335 335 336 + static int hub_port_status(struct usb_hub *hub, int port1, 337 + u16 *status, u16 *change) 338 + { 339 + int ret; 340 + 341 + mutex_lock(&hub->status_mutex); 342 + ret = get_port_status(hub->hdev, port1, &hub->status->port); 343 + if (ret < 4) { 344 + dev_err(hub->intfdev, 345 + "%s failed (err = %d)\n", __func__, ret); 346 + if (ret >= 0) 347 + ret = -EIO; 348 + } else { 349 + *status = le16_to_cpu(hub->status->port.wPortStatus); 350 + *change = le16_to_cpu(hub->status->port.wPortChange); 351 + ret = 0; 352 + } 353 + mutex_unlock(&hub->status_mutex); 354 + return ret; 355 + } 356 + 336 357 static void kick_khubd(struct usb_hub *hub) 337 358 { 338 359 unsigned long flags; ··· 631 610 } 632 611 633 612 /* caller has locked the hub device */ 634 - static int hub_pre_reset(struct usb_interface *intf) 613 + static void hub_stop(struct usb_hub *hub) 635 614 { 636 - struct usb_hub *hub = usb_get_intfdata(intf); 637 615 struct usb_device *hdev = hub->hdev; 638 616 int i; 639 617 ··· 642 622 usb_disconnect(&hdev->children[i]); 643 623 } 644 624 hub_quiesce(hub); 625 + } 626 + 627 + /* caller has locked the hub device */ 628 + static int hub_pre_reset(struct usb_interface *intf) 629 + { 630 + struct usb_hub *hub = usb_get_intfdata(intf); 631 + 632 + hub_stop(hub); 645 633 return 0; 646 634 } 647 635 ··· 938 910 939 911 /* Disconnect all children and quiesce the hub */ 940 912 hub->error = 0; 941 - hub_pre_reset(intf); 913 + hub_stop(hub); 942 914 943 915 usb_set_intfdata (intf, NULL); 944 916 ··· 1535 1507 out_authorized: 1536 1508 usb_unlock_device(usb_dev); // complements locktree 1537 1509 return result; 1538 - } 1539 - 1540 - 1541 - static int hub_port_status(struct usb_hub *hub, int port1, 1542 - u16 *status, u16 *change) 1543 - { 1544 - int ret; 1545 - 1546 - mutex_lock(&hub->status_mutex); 1547 - ret = get_port_status(hub->hdev, port1, &hub->status->port); 1548 - if (ret < 4) { 1549 - dev_err (hub->intfdev, 1550 - "%s failed (err = %d)\n", __FUNCTION__, ret); 1551 - if (ret >= 0) 1552 - ret = -EIO; 1553 - } else { 1554 - *status = le16_to_cpu(hub->status->port.wPortStatus); 1555 - *change = le16_to_cpu(hub->status->port.wPortChange); 1556 - ret = 0; 1557 - } 1558 - mutex_unlock(&hub->status_mutex); 1559 - return ret; 1560 1510 } 1561 1511 1562 1512 ··· 2732 2726 /* If the hub has died, clean up after it */ 2733 2727 if (hdev->state == USB_STATE_NOTATTACHED) { 2734 2728 hub->error = -ENODEV; 2735 - hub_pre_reset(intf); 2729 + hub_stop(hub); 2736 2730 goto loop; 2737 2731 } 2738 2732