Commit 9b32d10e authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

[PATCH] USB: core cleanups for struct usb_interface changes

Also set usb_device.dev.release right after initialization to catch any
early devices being destroyed.  I still think there's a few error paths
to correct, but this catches a lot of previous errors.
parent d62927a0
...@@ -309,7 +309,7 @@ static char *usb_dump_config ( ...@@ -309,7 +309,7 @@ static char *usb_dump_config (
return start + sprintf(start, "(null Cfg. desc.)\n"); return start + sprintf(start, "(null Cfg. desc.)\n");
start = usb_dump_config_descriptor(start, end, &config->desc, active); start = usb_dump_config_descriptor(start, end, &config->desc, active);
for (i = 0; i < config->desc.bNumInterfaces; i++) { for (i = 0; i < config->desc.bNumInterfaces; i++) {
interface = config->interface + i; interface = config->interface[i];
if (!interface) if (!interface)
break; break;
for (j = 0; j < interface->num_altsetting; j++) { for (j = 0; j < interface->num_altsetting; j++) {
......
...@@ -360,7 +360,7 @@ static int claimintf(struct dev_state *ps, unsigned int intf) ...@@ -360,7 +360,7 @@ static int claimintf(struct dev_state *ps, unsigned int intf)
/* already claimed */ /* already claimed */
if (test_bit(intf, &ps->ifclaimed)) if (test_bit(intf, &ps->ifclaimed))
return 0; return 0;
iface = &dev->actconfig->interface[intf]; iface = dev->actconfig->interface[intf];
err = -EBUSY; err = -EBUSY;
lock_kernel(); lock_kernel();
if (!usb_interface_claimed(iface)) { if (!usb_interface_claimed(iface)) {
...@@ -384,7 +384,7 @@ static int releaseintf(struct dev_state *ps, unsigned int intf) ...@@ -384,7 +384,7 @@ static int releaseintf(struct dev_state *ps, unsigned int intf)
dev = ps->dev; dev = ps->dev;
down(&dev->serialize); down(&dev->serialize);
if (dev && test_and_clear_bit(intf, &ps->ifclaimed)) { if (dev && test_and_clear_bit(intf, &ps->ifclaimed)) {
iface = &dev->actconfig->interface[intf]; iface = dev->actconfig->interface[intf];
usb_driver_release_interface(&usbdevfs_driver, iface); usb_driver_release_interface(&usbdevfs_driver, iface);
err = 0; err = 0;
} }
...@@ -414,7 +414,7 @@ static int findintfep(struct usb_device *dev, unsigned int ep) ...@@ -414,7 +414,7 @@ static int findintfep(struct usb_device *dev, unsigned int ep)
if (ep & ~(USB_DIR_IN|0xf)) if (ep & ~(USB_DIR_IN|0xf))
return -EINVAL; return -EINVAL;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
iface = &dev->actconfig->interface[i]; iface = dev->actconfig->interface[i];
for (j = 0; j < iface->num_altsetting; j++) { for (j = 0; j < iface->num_altsetting; j++) {
alts = &iface->altsetting[j]; alts = &iface->altsetting[j];
for (e = 0; e < alts->desc.bNumEndpoints; e++) { for (e = 0; e < alts->desc.bNumEndpoints; e++) {
...@@ -436,7 +436,7 @@ static int findintfif(struct usb_device *dev, unsigned int ifn) ...@@ -436,7 +436,7 @@ static int findintfif(struct usb_device *dev, unsigned int ifn)
if (ifn & ~0xff) if (ifn & ~0xff)
return -EINVAL; return -EINVAL;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
iface = &dev->actconfig->interface[i]; iface = dev->actconfig->interface[i];
for (j = 0; j < iface->num_altsetting; j++) { for (j = 0; j < iface->num_altsetting; j++) {
alts = &iface->altsetting[j]; alts = &iface->altsetting[j];
if (alts->desc.bInterfaceNumber == ifn) if (alts->desc.bInterfaceNumber == ifn)
...@@ -718,7 +718,7 @@ static int proc_resetdevice(struct dev_state *ps) ...@@ -718,7 +718,7 @@ static int proc_resetdevice(struct dev_state *ps)
return ret; return ret;
for (i = 0; i < ps->dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < ps->dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *intf = &ps->dev->actconfig->interface[i]; struct usb_interface *intf = ps->dev->actconfig->interface[i];
/* Don't simulate interfaces we've claimed */ /* Don't simulate interfaces we've claimed */
if (test_bit(i, &ps->ifclaimed)) if (test_bit(i, &ps->ifclaimed))
......
...@@ -60,7 +60,7 @@ static inline char *portspeed (int portstatus) ...@@ -60,7 +60,7 @@ static inline char *portspeed (int portstatus)
/* for dev_info, dev_dbg, etc */ /* for dev_info, dev_dbg, etc */
static inline struct device *hubdev (struct usb_device *dev) static inline struct device *hubdev (struct usb_device *dev)
{ {
return &dev->actconfig->interface [0].dev; return &dev->actconfig->interface[0]->dev;
} }
/* USB 2.0 spec Section 11.24.4.5 */ /* USB 2.0 spec Section 11.24.4.5 */
...@@ -691,7 +691,7 @@ static void hub_start_disconnect(struct usb_device *dev) ...@@ -691,7 +691,7 @@ static void hub_start_disconnect(struct usb_device *dev)
static int hub_port_status(struct usb_device *dev, int port, static int hub_port_status(struct usb_device *dev, int port,
u16 *status, u16 *change) u16 *status, u16 *change)
{ {
struct usb_hub *hub = usb_get_intfdata (dev->actconfig->interface); struct usb_hub *hub = usb_get_intfdata(dev->actconfig->interface[0]);
int ret; int ret;
ret = get_port_status(dev, port + 1, &hub->status->port); ret = get_port_status(dev, port + 1, &hub->status->port);
...@@ -1340,7 +1340,7 @@ int usb_physical_reset_device(struct usb_device *dev) ...@@ -1340,7 +1340,7 @@ int usb_physical_reset_device(struct usb_device *dev)
} }
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *intf = &dev->actconfig->interface[i]; struct usb_interface *intf = dev->actconfig->interface[i];
struct usb_interface_descriptor *as; struct usb_interface_descriptor *as;
as = &intf->altsetting[intf->act_altsetting].desc; as = &intf->altsetting[intf->act_altsetting].desc;
......
...@@ -675,7 +675,7 @@ void usb_set_maxpacket(struct usb_device *dev) ...@@ -675,7 +675,7 @@ void usb_set_maxpacket(struct usb_device *dev)
/* NOTE: affects all endpoints _except_ ep0 */ /* NOTE: affects all endpoints _except_ ep0 */
for (i=0; i<dev->actconfig->desc.bNumInterfaces; i++) { for (i=0; i<dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *ifp = dev->actconfig->interface + i; struct usb_interface *ifp = dev->actconfig->interface[i];
struct usb_host_interface *as = ifp->altsetting + ifp->act_altsetting; struct usb_host_interface *as = ifp->altsetting + ifp->act_altsetting;
struct usb_host_endpoint *ep = as->endpoint; struct usb_host_endpoint *ep = as->endpoint;
int e; int e;
......
...@@ -229,9 +229,9 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) ...@@ -229,9 +229,9 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
int i; int i;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
if (dev->actconfig->interface[i].altsetting[0] if (dev->actconfig->interface[i]->altsetting[0]
.desc.bInterfaceNumber == ifnum) .desc.bInterfaceNumber == ifnum)
return &dev->actconfig->interface[i]; return dev->actconfig->interface[i];
return NULL; return NULL;
} }
...@@ -256,14 +256,14 @@ usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum) ...@@ -256,14 +256,14 @@ usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
int i, j, k; int i, j, k;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
for (j = 0; j < dev->actconfig->interface[i].num_altsetting; j++) for (j = 0; j < dev->actconfig->interface[i]->num_altsetting; j++)
for (k = 0; k < dev->actconfig->interface[i] for (k = 0; k < dev->actconfig->interface[i]->
.altsetting[j].desc.bNumEndpoints; k++) altsetting[j].desc.bNumEndpoints; k++)
if (epnum == dev->actconfig->interface[i] if (epnum == dev->actconfig->interface[i]->
.altsetting[j].endpoint[k] altsetting[j].endpoint[k]
.desc.bEndpointAddress) .desc.bEndpointAddress)
return &dev->actconfig->interface[i] return &dev->actconfig->interface[i]->
.altsetting[j].endpoint[k] altsetting[j].endpoint[k]
.desc; .desc;
return NULL; return NULL;
...@@ -653,6 +653,26 @@ static int usb_hotplug (struct device *dev, char **envp, ...@@ -653,6 +653,26 @@ static int usb_hotplug (struct device *dev, char **envp,
#endif /* CONFIG_HOTPLUG */ #endif /* CONFIG_HOTPLUG */
/**
* usb_release_dev - free a usb device structure when all users of it are finished.
* @dev: device that's been disconnected
*
* Will be called only by the device core when all users of this usb device are
* done.
*/
static void usb_release_dev(struct device *dev)
{
struct usb_device *udev;
udev = to_usb_device(dev);
if (udev->bus && udev->bus->op && udev->bus->op->deallocate)
udev->bus->op->deallocate(udev);
usb_destroy_configuration(udev);
usb_bus_put(udev->bus);
kfree (udev);
}
/** /**
* usb_alloc_dev - allocate a usb device structure (usbcore-internal) * usb_alloc_dev - allocate a usb device structure (usbcore-internal)
* @parent: hub to which device is connected * @parent: hub to which device is connected
...@@ -681,6 +701,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus) ...@@ -681,6 +701,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus)
} }
device_initialize(&dev->dev); device_initialize(&dev->dev);
dev->dev.release = usb_release_dev;
dev->state = USB_STATE_ATTACHED; dev->state = USB_STATE_ATTACHED;
if (!parent) if (!parent)
...@@ -736,27 +757,6 @@ void usb_put_dev(struct usb_device *dev) ...@@ -736,27 +757,6 @@ void usb_put_dev(struct usb_device *dev)
put_device(&dev->dev); put_device(&dev->dev);
} }
/**
* usb_release_dev - free a usb device structure when all users of it are finished.
* @dev: device that's been disconnected
*
* Will be called only by the device core when all users of this usb device are
* done.
*/
static void usb_release_dev(struct device *dev)
{
struct usb_device *udev;
udev = to_usb_device(dev);
if (udev->bus && udev->bus->op && udev->bus->op->deallocate)
udev->bus->op->deallocate(udev);
usb_destroy_configuration (udev);
usb_bus_put (udev->bus);
kfree (udev);
}
static struct usb_device *match_device(struct usb_device *dev, static struct usb_device *match_device(struct usb_device *dev,
u16 vendor_id, u16 product_id) u16 vendor_id, u16 product_id)
{ {
...@@ -926,7 +926,7 @@ void usb_disconnect(struct usb_device **pdev) ...@@ -926,7 +926,7 @@ void usb_disconnect(struct usb_device **pdev)
struct usb_interface *interface; struct usb_interface *interface;
/* remove this interface */ /* remove this interface */
interface = &dev->actconfig->interface[i]; interface = dev->actconfig->interface[i];
device_unregister(&interface->dev); device_unregister(&interface->dev);
} }
} }
...@@ -1090,7 +1090,6 @@ int usb_new_device(struct usb_device *dev, struct device *parent) ...@@ -1090,7 +1090,6 @@ int usb_new_device(struct usb_device *dev, struct device *parent)
dev->dev.parent = parent; dev->dev.parent = parent;
dev->dev.driver = &usb_generic_driver; dev->dev.driver = &usb_generic_driver;
dev->dev.bus = &usb_bus_type; dev->dev.bus = &usb_bus_type;
dev->dev.release = usb_release_dev;
dev->dev.driver_data = &usb_generic_driver_data; dev->dev.driver_data = &usb_generic_driver_data;
usb_get_dev(dev); usb_get_dev(dev);
if (dev->dev.bus_id[0] == 0) if (dev->dev.bus_id[0] == 0)
...@@ -1216,7 +1215,7 @@ int usb_new_device(struct usb_device *dev, struct device *parent) ...@@ -1216,7 +1215,7 @@ int usb_new_device(struct usb_device *dev, struct device *parent)
/* Register all of the interfaces for this device with the driver core. /* Register all of the interfaces for this device with the driver core.
* Remember, interfaces get bound to drivers, not devices. */ * Remember, interfaces get bound to drivers, not devices. */
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *interface = &dev->actconfig->interface[i]; struct usb_interface *interface = dev->actconfig->interface[i];
struct usb_interface_descriptor *desc; struct usb_interface_descriptor *desc;
desc = &interface->altsetting [interface->act_altsetting].desc; desc = &interface->altsetting [interface->act_altsetting].desc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment