aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2006-08-30 11:32:52 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-27 14:58:56 -0400
commit1720058343fa43a1a25bfad9e62ea06e7e9743b6 (patch)
tree8225039836451d9784f729cf5136d5ad0443658c /drivers/usb
parentdd990f16a39d4e615c0b70a0ab50b79b32bfb16d (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')
-rw-r--r--drivers/usb/core/buffer.c4
-rw-r--r--drivers/usb/core/hcd.c67
-rw-r--r--drivers/usb/core/hcd.h13
-rw-r--r--drivers/usb/core/usb.c5
-rw-r--r--drivers/usb/gadget/dummy_hcd.c8
-rw-r--r--drivers/usb/host/ehci-dbg.c6
-rw-r--r--drivers/usb/host/ohci-dbg.c6
-rw-r--r--drivers/usb/mon/mon_main.c6
8 files changed, 44 insertions, 71 deletions
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index f4f4ef0f377a..840442a25b61 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -104,7 +104,7 @@ void *hcd_buffer_alloc (
104 dma_addr_t *dma 104 dma_addr_t *dma
105) 105)
106{ 106{
107 struct usb_hcd *hcd = bus->hcpriv; 107 struct usb_hcd *hcd = bus_to_hcd(bus);
108 int i; 108 int i;
109 109
110 /* some USB hosts just use PIO */ 110 /* some USB hosts just use PIO */
@@ -127,7 +127,7 @@ void hcd_buffer_free (
127 dma_addr_t dma 127 dma_addr_t dma
128) 128)
129{ 129{
130 struct usb_hcd *hcd = bus->hcpriv; 130 struct usb_hcd *hcd = bus_to_hcd(bus);
131 int i; 131 int i;
132 132
133 if (!addr) 133 if (!addr)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0cc14206920a..9dfc812de034 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 */
668struct usb_bus *usb_bus_get(struct usb_bus *bus)
669{
670 if (bus)
671 kref_get(&bus->kref);
672 return bus;
673}
674
675static 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 */
684void usb_bus_put(struct usb_bus *bus)
685{
686 if (bus)
687 kref_put(&bus->kref, usb_host_release);
688}
689
690/*-------------------------------------------------------------------------*/
691
692static struct class *usb_host_class; 667static struct class *usb_host_class;
693 668
694int usb_host_init(void) 669int 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)
1081int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) 1053int 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 */
1190int usb_hcd_get_frame_number (struct usb_device *udev) 1162int 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
1676static 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}
1726EXPORT_SYMBOL (usb_create_hcd); 1690EXPORT_SYMBOL (usb_create_hcd);
1727 1691
1692static 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
1699struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd)
1700{
1701 if (hcd)
1702 kref_get (&hcd->kref);
1703 return hcd;
1704}
1705EXPORT_SYMBOL (usb_get_hcd);
1706
1728void usb_put_hcd (struct usb_hcd *hcd) 1707void 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}
1733EXPORT_SYMBOL (usb_put_hcd); 1712EXPORT_SYMBOL (usb_put_hcd);
1734 1713
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 83e229914797..7a2bcba2ae61 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -55,12 +55,13 @@
55 55
56/*-------------------------------------------------------------------------*/ 56/*-------------------------------------------------------------------------*/
57 57
58struct usb_hcd { /* usb_bus.hcpriv points to this */ 58struct usb_hcd {
59 59
60 /* 60 /*
61 * housekeeping 61 * housekeeping
62 */ 62 */
63 struct usb_bus self; /* hcd is-a bus */ 63 struct usb_bus self; /* hcd is-a bus */
64 struct kref kref; /* reference counter */
64 65
65 const char *product_desc; /* product/vendor string */ 66 const char *product_desc; /* product/vendor string */
66 char irq_descr[24]; /* driver + bus # */ 67 char irq_descr[24]; /* driver + bus # */
@@ -129,8 +130,10 @@ static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd)
129 return &hcd->self; 130 return &hcd->self;
130} 131}
131 132
132 133static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus)
133// urb.hcpriv is really hardware-specific 134{
135 return container_of(bus, struct usb_hcd, self);
136}
134 137
135struct hcd_timeout { /* timeouts we allocate */ 138struct hcd_timeout { /* timeouts we allocate */
136 struct list_head timeout_list; 139 struct list_head timeout_list;
@@ -210,6 +213,7 @@ extern int usb_hcd_get_frame_number (struct usb_device *udev);
210 213
211extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, 214extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
212 struct device *dev, char *bus_name); 215 struct device *dev, char *bus_name);
216extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd);
213extern void usb_put_hcd (struct usb_hcd *hcd); 217extern void usb_put_hcd (struct usb_hcd *hcd);
214extern int usb_add_hcd(struct usb_hcd *hcd, 218extern int usb_add_hcd(struct usb_hcd *hcd,
215 unsigned int irqnum, unsigned long irqflags); 219 unsigned int irqnum, unsigned long irqflags);
@@ -356,9 +360,6 @@ extern struct list_head usb_bus_list;
356extern struct mutex usb_bus_list_lock; 360extern struct mutex usb_bus_list_lock;
357extern wait_queue_head_t usb_kill_urb_queue; 361extern wait_queue_head_t usb_kill_urb_queue;
358 362
359extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
360extern void usb_bus_put (struct usb_bus *bus);
361
362extern void usb_enable_root_hub_irq (struct usb_bus *bus); 363extern void usb_enable_root_hub_irq (struct usb_bus *bus);
363 364
364extern int usb_find_interface_driver (struct usb_device *dev, 365extern int usb_find_interface_driver (struct usb_device *dev,
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 7ab9d29215f8..b0c0a993338f 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -169,7 +169,7 @@ static void usb_release_dev(struct device *dev)
169 udev = to_usb_device(dev); 169 udev = to_usb_device(dev);
170 170
171 usb_destroy_configuration(udev); 171 usb_destroy_configuration(udev);
172 usb_bus_put(udev->bus); 172 usb_put_hcd(bus_to_hcd(udev->bus));
173 kfree(udev->product); 173 kfree(udev->product);
174 kfree(udev->manufacturer); 174 kfree(udev->manufacturer);
175 kfree(udev->serial); 175 kfree(udev->serial);
@@ -197,8 +197,7 @@ usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)
197 if (!dev) 197 if (!dev)
198 return NULL; 198 return NULL;
199 199
200 bus = usb_bus_get(bus); 200 if (!usb_get_hcd(bus_to_hcd(bus))) {
201 if (!bus) {
202 kfree(dev); 201 kfree(dev);
203 return NULL; 202 return NULL;
204 } 203 }
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 7d1c22c34957..fdab97a27c08 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -889,11 +889,9 @@ EXPORT_SYMBOL (net2280_set_fifo_mode);
889static void 889static void
890dummy_gadget_release (struct device *dev) 890dummy_gadget_release (struct device *dev)
891{ 891{
892#if 0 /* usb_bus_put isn't EXPORTed! */
893 struct dummy *dum = gadget_dev_to_dummy (dev); 892 struct dummy *dum = gadget_dev_to_dummy (dev);
894 893
895 usb_bus_put (&dummy_to_hcd (dum)->self); 894 usb_put_hcd (dummy_to_hcd (dum));
896#endif
897} 895}
898 896
899static int dummy_udc_probe (struct platform_device *pdev) 897static int dummy_udc_probe (struct platform_device *pdev)
@@ -915,9 +913,7 @@ static int dummy_udc_probe (struct platform_device *pdev)
915 if (rc < 0) 913 if (rc < 0)
916 return rc; 914 return rc;
917 915
918#if 0 /* usb_bus_get isn't EXPORTed! */ 916 usb_get_hcd (dummy_to_hcd (dum));
919 usb_bus_get (&dummy_to_hcd (dum)->self);
920#endif
921 917
922 platform_set_drvdata (pdev, dum); 918 platform_set_drvdata (pdev, dum);
923 device_create_file (&dum->gadget.dev, &dev_attr_function); 919 device_create_file (&dum->gadget.dev, &dev_attr_function);
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 65ac9fef3a7c..215ce6d06394 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -451,7 +451,7 @@ show_async (struct class_device *class_dev, char *buf)
451 *buf = 0; 451 *buf = 0;
452 452
453 bus = class_get_devdata(class_dev); 453 bus = class_get_devdata(class_dev);
454 hcd = bus->hcpriv; 454 hcd = bus_to_hcd(bus);
455 ehci = hcd_to_ehci (hcd); 455 ehci = hcd_to_ehci (hcd);
456 next = buf; 456 next = buf;
457 size = PAGE_SIZE; 457 size = PAGE_SIZE;
@@ -497,7 +497,7 @@ show_periodic (struct class_device *class_dev, char *buf)
497 seen_count = 0; 497 seen_count = 0;
498 498
499 bus = class_get_devdata(class_dev); 499 bus = class_get_devdata(class_dev);
500 hcd = bus->hcpriv; 500 hcd = bus_to_hcd(bus);
501 ehci = hcd_to_ehci (hcd); 501 ehci = hcd_to_ehci (hcd);
502 next = buf; 502 next = buf;
503 size = PAGE_SIZE; 503 size = PAGE_SIZE;
@@ -634,7 +634,7 @@ show_registers (struct class_device *class_dev, char *buf)
634 static char label [] = ""; 634 static char label [] = "";
635 635
636 bus = class_get_devdata(class_dev); 636 bus = class_get_devdata(class_dev);
637 hcd = bus->hcpriv; 637 hcd = bus_to_hcd(bus);
638 ehci = hcd_to_ehci (hcd); 638 ehci = hcd_to_ehci (hcd);
639 next = buf; 639 next = buf;
640 size = PAGE_SIZE; 640 size = PAGE_SIZE;
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index da52609a9290..534d07dcb824 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -477,7 +477,7 @@ show_async (struct class_device *class_dev, char *buf)
477 unsigned long flags; 477 unsigned long flags;
478 478
479 bus = class_get_devdata(class_dev); 479 bus = class_get_devdata(class_dev);
480 hcd = bus->hcpriv; 480 hcd = bus_to_hcd(bus);
481 ohci = hcd_to_ohci(hcd); 481 ohci = hcd_to_ohci(hcd);
482 482
483 /* display control and bulk lists together, for simplicity */ 483 /* display control and bulk lists together, for simplicity */
@@ -510,7 +510,7 @@ show_periodic (struct class_device *class_dev, char *buf)
510 seen_count = 0; 510 seen_count = 0;
511 511
512 bus = class_get_devdata(class_dev); 512 bus = class_get_devdata(class_dev);
513 hcd = bus->hcpriv; 513 hcd = bus_to_hcd(bus);
514 ohci = hcd_to_ohci(hcd); 514 ohci = hcd_to_ohci(hcd);
515 next = buf; 515 next = buf;
516 size = PAGE_SIZE; 516 size = PAGE_SIZE;
@@ -607,7 +607,7 @@ show_registers (struct class_device *class_dev, char *buf)
607 u32 rdata; 607 u32 rdata;
608 608
609 bus = class_get_devdata(class_dev); 609 bus = class_get_devdata(class_dev);
610 hcd = bus->hcpriv; 610 hcd = bus_to_hcd(bus);
611 ohci = hcd_to_ohci(hcd); 611 ohci = hcd_to_ohci(hcd);
612 regs = ohci->regs; 612 regs = ohci->regs;
613 next = buf; 613 next = buf;
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index 275a66f83058..e0ed36cdfd8b 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -265,7 +265,6 @@ static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus)
265 ubus->mon_bus = NULL; 265 ubus->mon_bus = NULL;
266 mbus->u_bus = NULL; 266 mbus->u_bus = NULL;
267 mb(); 267 mb();
268 // usb_bus_put(ubus);
269} 268}
270 269
271/* 270/*
@@ -297,10 +296,9 @@ static void mon_bus_init(struct dentry *mondir, struct usb_bus *ubus)
297 INIT_LIST_HEAD(&mbus->r_list); 296 INIT_LIST_HEAD(&mbus->r_list);
298 297
299 /* 298 /*
300 * This usb_bus_get here is superfluous, because we receive 299 * We don't need to take a reference to ubus, because we receive
301 * a notification if usb_bus is about to be removed. 300 * a notification if the bus is about to be removed.
302 */ 301 */
303 // usb_bus_get(ubus);
304 mbus->u_bus = ubus; 302 mbus->u_bus = ubus;
305 ubus->mon_bus = mbus; 303 ubus->mon_bus = mbus;
306 304