aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core
diff options
context:
space:
mode:
authorLan Tianyu <tianyu.lan@intel.com>2012-05-11 04:08:29 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-05-11 20:08:41 -0400
commitf397d7c4c5e8a1eb93f2ed15808a509318ccf1dd (patch)
tree6cc7619ed9811d058dccb67b95b2692e48723199 /drivers/usb/core
parent54d3f8c63d6940966217b807972778fb17c3fa82 (diff)
usb: add struct usb_hub_port to store port related members.
Add struct usb_hub_port pointer port_data in the struct usb_hub and allocate struct usb_hub_port perspectively for each ports to store private data. Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/core')
-rw-r--r--drivers/usb/core/hub.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index ec6c97dadbe4..0c17d5a91d79 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -37,6 +37,10 @@
37#endif 37#endif
38#endif 38#endif
39 39
40struct usb_hub_port {
41 void *port_owner;
42};
43
40struct usb_hub { 44struct usb_hub {
41 struct device *intfdev; /* the "interface" device */ 45 struct device *intfdev; /* the "interface" device */
42 struct usb_device *hdev; 46 struct usb_device *hdev;
@@ -81,7 +85,7 @@ struct usb_hub {
81 u8 indicator[USB_MAXCHILDREN]; 85 u8 indicator[USB_MAXCHILDREN];
82 struct delayed_work leds; 86 struct delayed_work leds;
83 struct delayed_work init_work; 87 struct delayed_work init_work;
84 void **port_owners; 88 struct usb_hub_port *port_data;
85}; 89};
86 90
87static inline int hub_is_superspeed(struct usb_device *hdev) 91static inline int hub_is_superspeed(struct usb_device *hdev)
@@ -1049,8 +1053,9 @@ static int hub_configure(struct usb_hub *hub,
1049 1053
1050 hdev->children = kzalloc(hdev->maxchild * 1054 hdev->children = kzalloc(hdev->maxchild *
1051 sizeof(struct usb_device *), GFP_KERNEL); 1055 sizeof(struct usb_device *), GFP_KERNEL);
1052 hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL); 1056 hub->port_data = kzalloc(hdev->maxchild * sizeof(struct usb_hub_port),
1053 if (!hdev->children || !hub->port_owners) { 1057 GFP_KERNEL);
1058 if (!hub->port_data || !hdev->children) {
1054 ret = -ENOMEM; 1059 ret = -ENOMEM;
1055 goto fail; 1060 goto fail;
1056 } 1061 }
@@ -1305,7 +1310,7 @@ static void hub_disconnect(struct usb_interface *intf)
1305 1310
1306 usb_free_urb(hub->urb); 1311 usb_free_urb(hub->urb);
1307 kfree(hdev->children); 1312 kfree(hdev->children);
1308 kfree(hub->port_owners); 1313 kfree(hub->port_data);
1309 kfree(hub->descriptor); 1314 kfree(hub->descriptor);
1310 kfree(hub->status); 1315 kfree(hub->status);
1311 kfree(hub->buffer); 1316 kfree(hub->buffer);
@@ -1437,7 +1442,7 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1,
1437 /* This assumes that devices not managed by the hub driver 1442 /* This assumes that devices not managed by the hub driver
1438 * will always have maxchild equal to 0. 1443 * will always have maxchild equal to 0.
1439 */ 1444 */
1440 *ppowner = &(hdev_to_hub(hdev)->port_owners[port1 - 1]); 1445 *ppowner = &(hdev_to_hub(hdev)->port_data[port1 - 1].port_owner);
1441 return 0; 1446 return 0;
1442} 1447}
1443 1448
@@ -1472,16 +1477,14 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)
1472 1477
1473void usb_hub_release_all_ports(struct usb_device *hdev, void *owner) 1478void usb_hub_release_all_ports(struct usb_device *hdev, void *owner)
1474{ 1479{
1480 struct usb_hub *hub = hdev_to_hub(hdev);
1475 int n; 1481 int n;
1476 void **powner;
1477 1482
1478 n = find_port_owner(hdev, 1, &powner); 1483 for (n = 0; n < hdev->maxchild; n++) {
1479 if (n == 0) { 1484 if (hub->port_data[n].port_owner == owner)
1480 for (; n < hdev->maxchild; (++n, ++powner)) { 1485 hub->port_data[n].port_owner = NULL;
1481 if (*powner == owner)
1482 *powner = NULL;
1483 }
1484 } 1486 }
1487
1485} 1488}
1486 1489
1487/* The caller must hold udev's lock */ 1490/* The caller must hold udev's lock */
@@ -1492,7 +1495,7 @@ bool usb_device_is_owned(struct usb_device *udev)
1492 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) 1495 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent)
1493 return false; 1496 return false;
1494 hub = hdev_to_hub(udev->parent); 1497 hub = hdev_to_hub(udev->parent);
1495 return !!hub->port_owners[udev->portnum - 1]; 1498 return !!hub->port_data[udev->portnum - 1].port_owner;
1496} 1499}
1497 1500
1498 1501