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 (
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++) {
......
......@@ -360,7 +360,7 @@ static int claimintf(struct dev_state *ps, unsigned int intf)
/* 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 @@ static int releaseintf(struct dev_state *ps, unsigned int intf)
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 @@ static int findintfep(struct usb_device *dev, unsigned int ep)
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 @@ static int findintfif(struct usb_device *dev, unsigned int ifn)
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 @@ static int proc_resetdevice(struct dev_state *ps)
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))
......
......@@ -60,7 +60,7 @@ static inline char *portspeed (int portstatus)
/* 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 void hub_start_disconnect(struct usb_device *dev)
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 @@ int usb_physical_reset_device(struct usb_device *dev)
}
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;
......
......@@ -675,7 +675,7 @@ void usb_set_maxpacket(struct usb_device *dev)
/* NOTE: affects all endpoints _except_ ep0 */
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_endpoint *ep = as->endpoint;
int e;
......
......@@ -229,9 +229,9 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
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 @@ usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
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;
......@@ -653,6 +653,26 @@ static int usb_hotplug (struct device *dev, char **envp,
#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
......@@ -681,6 +701,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus)
}
device_initialize(&dev->dev);
dev->dev.release = usb_release_dev;
dev->state = USB_STATE_ATTACHED;
if (!parent)
......@@ -736,27 +757,6 @@ void usb_put_dev(struct usb_device *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,
u16 vendor_id, u16 product_id)
{
......@@ -926,7 +926,7 @@ void usb_disconnect(struct usb_device **pdev)
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 @@ int usb_new_device(struct usb_device *dev, struct device *parent)
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 @@ int usb_new_device(struct usb_device *dev, struct device *parent)
/* 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;
......
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