提交 f397d7c4 编写于 作者: L Lan Tianyu 提交者: Greg Kroah-Hartman

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: NLan Tianyu <tianyu.lan@intel.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 54d3f8c6
...@@ -37,6 +37,10 @@ ...@@ -37,6 +37,10 @@
#endif #endif
#endif #endif
struct usb_hub_port {
void *port_owner;
};
struct usb_hub { struct usb_hub {
struct device *intfdev; /* the "interface" device */ struct device *intfdev; /* the "interface" device */
struct usb_device *hdev; struct usb_device *hdev;
...@@ -81,7 +85,7 @@ struct usb_hub { ...@@ -81,7 +85,7 @@ struct usb_hub {
u8 indicator[USB_MAXCHILDREN]; u8 indicator[USB_MAXCHILDREN];
struct delayed_work leds; struct delayed_work leds;
struct delayed_work init_work; struct delayed_work init_work;
void **port_owners; struct usb_hub_port *port_data;
}; };
static inline int hub_is_superspeed(struct usb_device *hdev) static inline int hub_is_superspeed(struct usb_device *hdev)
...@@ -1049,8 +1053,9 @@ static int hub_configure(struct usb_hub *hub, ...@@ -1049,8 +1053,9 @@ static int hub_configure(struct usb_hub *hub,
hdev->children = kzalloc(hdev->maxchild * hdev->children = kzalloc(hdev->maxchild *
sizeof(struct usb_device *), GFP_KERNEL); sizeof(struct usb_device *), GFP_KERNEL);
hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL); hub->port_data = kzalloc(hdev->maxchild * sizeof(struct usb_hub_port),
if (!hdev->children || !hub->port_owners) { GFP_KERNEL);
if (!hub->port_data || !hdev->children) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail; goto fail;
} }
...@@ -1305,7 +1310,7 @@ static void hub_disconnect(struct usb_interface *intf) ...@@ -1305,7 +1310,7 @@ static void hub_disconnect(struct usb_interface *intf)
usb_free_urb(hub->urb); usb_free_urb(hub->urb);
kfree(hdev->children); kfree(hdev->children);
kfree(hub->port_owners); kfree(hub->port_data);
kfree(hub->descriptor); kfree(hub->descriptor);
kfree(hub->status); kfree(hub->status);
kfree(hub->buffer); kfree(hub->buffer);
...@@ -1437,7 +1442,7 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1, ...@@ -1437,7 +1442,7 @@ static int find_port_owner(struct usb_device *hdev, unsigned port1,
/* This assumes that devices not managed by the hub driver /* This assumes that devices not managed by the hub driver
* will always have maxchild equal to 0. * will always have maxchild equal to 0.
*/ */
*ppowner = &(hdev_to_hub(hdev)->port_owners[port1 - 1]); *ppowner = &(hdev_to_hub(hdev)->port_data[port1 - 1].port_owner);
return 0; return 0;
} }
...@@ -1472,16 +1477,14 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner) ...@@ -1472,16 +1477,14 @@ int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)
void usb_hub_release_all_ports(struct usb_device *hdev, void *owner) void usb_hub_release_all_ports(struct usb_device *hdev, void *owner)
{ {
struct usb_hub *hub = hdev_to_hub(hdev);
int n; int n;
void **powner;
n = find_port_owner(hdev, 1, &powner); for (n = 0; n < hdev->maxchild; n++) {
if (n == 0) { if (hub->port_data[n].port_owner == owner)
for (; n < hdev->maxchild; (++n, ++powner)) { hub->port_data[n].port_owner = NULL;
if (*powner == owner)
*powner = NULL;
}
} }
} }
/* The caller must hold udev's lock */ /* The caller must hold udev's lock */
...@@ -1492,7 +1495,7 @@ bool usb_device_is_owned(struct usb_device *udev) ...@@ -1492,7 +1495,7 @@ bool usb_device_is_owned(struct usb_device *udev)
if (udev->state == USB_STATE_NOTATTACHED || !udev->parent) if (udev->state == USB_STATE_NOTATTACHED || !udev->parent)
return false; return false;
hub = hdev_to_hub(udev->parent); hub = hdev_to_hub(udev->parent);
return !!hub->port_owners[udev->portnum - 1]; return !!hub->port_data[udev->portnum - 1].port_owner;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册