ChangeSet 1.1595.7.2, 2003/07/29 11:40:03-07:00, greg@kroah.com [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. drivers/usb/core/devices.c | 2 - drivers/usb/core/devio.c | 10 +++--- drivers/usb/core/hub.c | 6 ++-- drivers/usb/core/message.c | 2 - drivers/usb/core/usb.c | 65 ++++++++++++++++++++++----------------------- 5 files changed, 42 insertions(+), 43 deletions(-) diff -Nru a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c --- a/drivers/usb/core/devices.c Fri Aug 1 10:56:57 2003 +++ b/drivers/usb/core/devices.c Fri Aug 1 10:56:57 2003 @@ -309,7 +309,7 @@ return start + sprintf(start, "(null Cfg. desc.)\n"); start = usb_dump_config_descriptor(start, end, &config->desc, active); for (i = 0; i < config->desc.bNumInterfaces; i++) { - interface = config->interface + i; + interface = config->interface[i]; if (!interface) break; for (j = 0; j < interface->num_altsetting; j++) { diff -Nru a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c --- a/drivers/usb/core/devio.c Fri Aug 1 10:56:57 2003 +++ b/drivers/usb/core/devio.c Fri Aug 1 10:56:57 2003 @@ -360,7 +360,7 @@ /* already claimed */ if (test_bit(intf, &ps->ifclaimed)) return 0; - iface = &dev->actconfig->interface[intf]; + iface = dev->actconfig->interface[intf]; err = -EBUSY; lock_kernel(); if (!usb_interface_claimed(iface)) { @@ -384,7 +384,7 @@ dev = ps->dev; down(&dev->serialize); 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); err = 0; } @@ -414,7 +414,7 @@ if (ep & ~(USB_DIR_IN|0xf)) return -EINVAL; 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++) { alts = &iface->altsetting[j]; for (e = 0; e < alts->desc.bNumEndpoints; e++) { @@ -436,7 +436,7 @@ if (ifn & ~0xff) return -EINVAL; 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++) { alts = &iface->altsetting[j]; if (alts->desc.bInterfaceNumber == ifn) @@ -718,7 +718,7 @@ return ret; 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 */ if (test_bit(i, &ps->ifclaimed)) diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c --- a/drivers/usb/core/hub.c Fri Aug 1 10:56:57 2003 +++ b/drivers/usb/core/hub.c Fri Aug 1 10:56:57 2003 @@ -60,7 +60,7 @@ /* for dev_info, dev_dbg, etc */ 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 */ @@ -691,7 +691,7 @@ static int hub_port_status(struct usb_device *dev, int port, 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; ret = get_port_status(dev, port + 1, &hub->status->port); @@ -1340,7 +1340,7 @@ } 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; as = &intf->altsetting[intf->act_altsetting].desc; diff -Nru a/drivers/usb/core/message.c b/drivers/usb/core/message.c --- a/drivers/usb/core/message.c Fri Aug 1 10:56:57 2003 +++ b/drivers/usb/core/message.c Fri Aug 1 10:56:57 2003 @@ -675,7 +675,7 @@ /* NOTE: affects all endpoints _except_ ep0 */ for (i=0; iactconfig->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_endpoint *ep = as->endpoint; int e; diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c --- a/drivers/usb/core/usb.c Fri Aug 1 10:56:57 2003 +++ b/drivers/usb/core/usb.c Fri Aug 1 10:56:57 2003 @@ -229,9 +229,9 @@ int 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) - return &dev->actconfig->interface[i]; + return dev->actconfig->interface[i]; return NULL; } @@ -256,14 +256,14 @@ int i, j, k; for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) - for (j = 0; j < dev->actconfig->interface[i].num_altsetting; j++) - for (k = 0; k < dev->actconfig->interface[i] - .altsetting[j].desc.bNumEndpoints; k++) - if (epnum == dev->actconfig->interface[i] - .altsetting[j].endpoint[k] + for (j = 0; j < dev->actconfig->interface[i]->num_altsetting; j++) + for (k = 0; k < dev->actconfig->interface[i]-> + altsetting[j].desc.bNumEndpoints; k++) + if (epnum == dev->actconfig->interface[i]-> + altsetting[j].endpoint[k] .desc.bEndpointAddress) - return &dev->actconfig->interface[i] - .altsetting[j].endpoint[k] + return &dev->actconfig->interface[i]-> + altsetting[j].endpoint[k] .desc; return NULL; @@ -654,6 +654,26 @@ #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) * @parent: hub to which device is connected * @bus: bus used to access the device @@ -681,6 +701,7 @@ } device_initialize(&dev->dev); + dev->dev.release = usb_release_dev; dev->state = USB_STATE_ATTACHED; if (!parent) @@ -736,27 +757,6 @@ 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, u16 vendor_id, u16 product_id) { @@ -926,7 +926,7 @@ struct usb_interface *interface; /* remove this interface */ - interface = &dev->actconfig->interface[i]; + interface = dev->actconfig->interface[i]; device_unregister(&interface->dev); } } @@ -1090,7 +1090,6 @@ dev->dev.parent = parent; dev->dev.driver = &usb_generic_driver; dev->dev.bus = &usb_bus_type; - dev->dev.release = usb_release_dev; dev->dev.driver_data = &usb_generic_driver_data; usb_get_dev(dev); if (dev->dev.bus_id[0] == 0) @@ -1216,7 +1215,7 @@ /* Register all of the interfaces for this device with the driver core. * Remember, interfaces get bound to drivers, not devices. */ 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; desc = &interface->altsetting [interface->act_altsetting].desc;