diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2006-08-30 11:32:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-27 14:58:56 -0400 |
commit | 1720058343fa43a1a25bfad9e62ea06e7e9743b6 (patch) | |
tree | 8225039836451d9784f729cf5136d5ad0443658c /drivers/usb/core/hcd.c | |
parent | dd990f16a39d4e615c0b70a0ab50b79b32bfb16d (diff) |
usbcore: trim down usb_bus structure
As part of the ongoing program to flatten out the HCD bus-glue layer,
this patch (as771b) eliminates the hcpriv, release, and kref fields
from struct usb_bus. hcpriv and release were not being used for
anything worthwhile, and kref has been moved into the enclosing
usb_hcd structure.
Along with those changes, the patch gets rid of usb_bus_get and
usb_bus_put, replacing them with usb_get_hcd and usb_put_hcd.
The one interesting aspect is that the dev_set_drvdata call was
removed from usb_put_hcd, where it clearly doesn't belong. This means
the driver private data won't get reset to NULL. It shouldn't cause
any problems, since the private data is undefined when no driver is
bound.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/hcd.c')
-rw-r--r-- | drivers/usb/core/hcd.c | 67 |
1 files changed, 23 insertions, 44 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 0cc14206920..9dfc812de03 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -664,31 +664,6 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) | |||
664 | 664 | ||
665 | /*-------------------------------------------------------------------------*/ | 665 | /*-------------------------------------------------------------------------*/ |
666 | 666 | ||
667 | /* exported only within usbcore */ | ||
668 | struct usb_bus *usb_bus_get(struct usb_bus *bus) | ||
669 | { | ||
670 | if (bus) | ||
671 | kref_get(&bus->kref); | ||
672 | return bus; | ||
673 | } | ||
674 | |||
675 | static void usb_host_release(struct kref *kref) | ||
676 | { | ||
677 | struct usb_bus *bus = container_of(kref, struct usb_bus, kref); | ||
678 | |||
679 | if (bus->release) | ||
680 | bus->release(bus); | ||
681 | } | ||
682 | |||
683 | /* exported only within usbcore */ | ||
684 | void usb_bus_put(struct usb_bus *bus) | ||
685 | { | ||
686 | if (bus) | ||
687 | kref_put(&bus->kref, usb_host_release); | ||
688 | } | ||
689 | |||
690 | /*-------------------------------------------------------------------------*/ | ||
691 | |||
692 | static struct class *usb_host_class; | 667 | static struct class *usb_host_class; |
693 | 668 | ||
694 | int usb_host_init(void) | 669 | int usb_host_init(void) |
@@ -720,15 +695,12 @@ static void usb_bus_init (struct usb_bus *bus) | |||
720 | bus->devnum_next = 1; | 695 | bus->devnum_next = 1; |
721 | 696 | ||
722 | bus->root_hub = NULL; | 697 | bus->root_hub = NULL; |
723 | bus->hcpriv = NULL; | ||
724 | bus->busnum = -1; | 698 | bus->busnum = -1; |
725 | bus->bandwidth_allocated = 0; | 699 | bus->bandwidth_allocated = 0; |
726 | bus->bandwidth_int_reqs = 0; | 700 | bus->bandwidth_int_reqs = 0; |
727 | bus->bandwidth_isoc_reqs = 0; | 701 | bus->bandwidth_isoc_reqs = 0; |
728 | 702 | ||
729 | INIT_LIST_HEAD (&bus->bus_list); | 703 | INIT_LIST_HEAD (&bus->bus_list); |
730 | |||
731 | kref_init(&bus->kref); | ||
732 | } | 704 | } |
733 | 705 | ||
734 | /*-------------------------------------------------------------------------*/ | 706 | /*-------------------------------------------------------------------------*/ |
@@ -1081,7 +1053,7 @@ static void urb_unlink (struct urb *urb) | |||
1081 | int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | 1053 | int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) |
1082 | { | 1054 | { |
1083 | int status; | 1055 | int status; |
1084 | struct usb_hcd *hcd = urb->dev->bus->hcpriv; | 1056 | struct usb_hcd *hcd = bus_to_hcd(urb->dev->bus); |
1085 | struct usb_host_endpoint *ep; | 1057 | struct usb_host_endpoint *ep; |
1086 | unsigned long flags; | 1058 | unsigned long flags; |
1087 | 1059 | ||
@@ -1189,7 +1161,8 @@ done: | |||
1189 | /* called in any context */ | 1161 | /* called in any context */ |
1190 | int usb_hcd_get_frame_number (struct usb_device *udev) | 1162 | int usb_hcd_get_frame_number (struct usb_device *udev) |
1191 | { | 1163 | { |
1192 | struct usb_hcd *hcd = (struct usb_hcd *)udev->bus->hcpriv; | 1164 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); |
1165 | |||
1193 | if (!HC_IS_RUNNING (hcd->state)) | 1166 | if (!HC_IS_RUNNING (hcd->state)) |
1194 | return -ESHUTDOWN; | 1167 | return -ESHUTDOWN; |
1195 | return hcd->driver->get_frame_number (hcd); | 1168 | return hcd->driver->get_frame_number (hcd); |
@@ -1262,7 +1235,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1262 | spin_lock (&hcd_data_lock); | 1235 | spin_lock (&hcd_data_lock); |
1263 | 1236 | ||
1264 | sys = &urb->dev->dev; | 1237 | sys = &urb->dev->dev; |
1265 | hcd = urb->dev->bus->hcpriv; | 1238 | hcd = bus_to_hcd(urb->dev->bus); |
1266 | if (hcd == NULL) { | 1239 | if (hcd == NULL) { |
1267 | retval = -ENODEV; | 1240 | retval = -ENODEV; |
1268 | goto done; | 1241 | goto done; |
@@ -1333,7 +1306,7 @@ void usb_hcd_endpoint_disable (struct usb_device *udev, | |||
1333 | struct usb_hcd *hcd; | 1306 | struct usb_hcd *hcd; |
1334 | struct urb *urb; | 1307 | struct urb *urb; |
1335 | 1308 | ||
1336 | hcd = udev->bus->hcpriv; | 1309 | hcd = bus_to_hcd(udev->bus); |
1337 | 1310 | ||
1338 | WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT && | 1311 | WARN_ON (!HC_IS_RUNNING (hcd->state) && hcd->state != HC_STATE_HALT && |
1339 | udev->state != USB_STATE_NOTATTACHED); | 1312 | udev->state != USB_STATE_NOTATTACHED); |
@@ -1673,14 +1646,6 @@ EXPORT_SYMBOL_GPL (usb_hc_died); | |||
1673 | 1646 | ||
1674 | /*-------------------------------------------------------------------------*/ | 1647 | /*-------------------------------------------------------------------------*/ |
1675 | 1648 | ||
1676 | static void hcd_release (struct usb_bus *bus) | ||
1677 | { | ||
1678 | struct usb_hcd *hcd; | ||
1679 | |||
1680 | hcd = container_of(bus, struct usb_hcd, self); | ||
1681 | kfree(hcd); | ||
1682 | } | ||
1683 | |||
1684 | /** | 1649 | /** |
1685 | * usb_create_hcd - create and initialize an HCD structure | 1650 | * usb_create_hcd - create and initialize an HCD structure |
1686 | * @driver: HC driver that will use this hcd | 1651 | * @driver: HC driver that will use this hcd |
@@ -1705,10 +1670,9 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
1705 | return NULL; | 1670 | return NULL; |
1706 | } | 1671 | } |
1707 | dev_set_drvdata(dev, hcd); | 1672 | dev_set_drvdata(dev, hcd); |
1673 | kref_init(&hcd->kref); | ||
1708 | 1674 | ||
1709 | usb_bus_init(&hcd->self); | 1675 | usb_bus_init(&hcd->self); |
1710 | hcd->self.hcpriv = hcd; | ||
1711 | hcd->self.release = &hcd_release; | ||
1712 | hcd->self.controller = dev; | 1676 | hcd->self.controller = dev; |
1713 | hcd->self.bus_name = bus_name; | 1677 | hcd->self.bus_name = bus_name; |
1714 | hcd->self.uses_dma = (dev->dma_mask != NULL); | 1678 | hcd->self.uses_dma = (dev->dma_mask != NULL); |
@@ -1725,10 +1689,25 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, | |||
1725 | } | 1689 | } |
1726 | EXPORT_SYMBOL (usb_create_hcd); | 1690 | EXPORT_SYMBOL (usb_create_hcd); |
1727 | 1691 | ||
1692 | static void hcd_release (struct kref *kref) | ||
1693 | { | ||
1694 | struct usb_hcd *hcd = container_of (kref, struct usb_hcd, kref); | ||
1695 | |||
1696 | kfree(hcd); | ||
1697 | } | ||
1698 | |||
1699 | struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd) | ||
1700 | { | ||
1701 | if (hcd) | ||
1702 | kref_get (&hcd->kref); | ||
1703 | return hcd; | ||
1704 | } | ||
1705 | EXPORT_SYMBOL (usb_get_hcd); | ||
1706 | |||
1728 | void usb_put_hcd (struct usb_hcd *hcd) | 1707 | void usb_put_hcd (struct usb_hcd *hcd) |
1729 | { | 1708 | { |
1730 | dev_set_drvdata(hcd->self.controller, NULL); | 1709 | if (hcd) |
1731 | usb_bus_put(&hcd->self); | 1710 | kref_put (&hcd->kref, hcd_release); |
1732 | } | 1711 | } |
1733 | EXPORT_SYMBOL (usb_put_hcd); | 1712 | EXPORT_SYMBOL (usb_put_hcd); |
1734 | 1713 | ||