Commit 6e8339b9 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

[PATCH] USB: Don't dereference NULL actconfig

This patch fixes a simple error in a couple of utility routines.  They
will no longer try to dereference a NULL actconfig pointer.  Also, they
will work a little better if the configuration is changed while they are
running (which should never happen anyway).
parent 9b79ea41
...@@ -206,12 +206,15 @@ void usb_deregister(struct usb_driver *driver) ...@@ -206,12 +206,15 @@ void usb_deregister(struct usb_driver *driver)
*/ */
struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
{ {
struct usb_host_config *config = dev->actconfig;
int i; int i;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) if (!config)
if (dev->actconfig->interface[i]->altsetting[0] return NULL;
for (i = 0; i < config->desc.bNumInterfaces; i++)
if (config->interface[i]->altsetting[0]
.desc.bInterfaceNumber == ifnum) .desc.bInterfaceNumber == ifnum)
return dev->actconfig->interface[i]; return config->interface[i];
return NULL; return NULL;
} }
...@@ -233,14 +236,17 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum) ...@@ -233,14 +236,17 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
struct usb_endpoint_descriptor * struct usb_endpoint_descriptor *
usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum) usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
{ {
struct usb_host_config *config = dev->actconfig;
int i, k; int i, k;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { if (!config)
return NULL;
for (i = 0; i < config->desc.bNumInterfaces; i++) {
struct usb_interface *intf; struct usb_interface *intf;
struct usb_host_interface *alt; struct usb_host_interface *alt;
/* only endpoints in current altseting are active */ /* only endpoints in current altsetting are active */
intf = dev->actconfig->interface[i]; intf = config->interface[i];
alt = intf->altsetting + intf->act_altsetting; alt = intf->altsetting + intf->act_altsetting;
for (k = 0; k < alt->desc.bNumEndpoints; k++) for (k = 0; k < alt->desc.bNumEndpoints; k++)
......
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