]> git.hungrycats.org Git - linux/commitdiff
[PATCH] USB: Don't dereference NULL actconfig
authorAlan Stern <stern@rowland.harvard.edu>
Mon, 26 Jan 2004 09:11:51 +0000 (01:11 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Mon, 26 Jan 2004 09:11:51 +0000 (01:11 -0800)
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).

drivers/usb/core/usb.c

index 05a7a9f8fa551c944bf8eb112cd4581131181807..89d18fa37d0b2cf52b550881dcd74cc2a64b8cf4 100644 (file)
@@ -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_host_config *config = dev->actconfig;
        int i;
 
-       for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
-               if (dev->actconfig->interface[i]->altsetting[0]
+       if (!config)
+               return NULL;
+       for (i = 0; i < config->desc.bNumInterfaces; i++)
+               if (config->interface[i]->altsetting[0]
                                .desc.bInterfaceNumber == ifnum)
-                       return dev->actconfig->interface[i];
+                       return config->interface[i];
 
        return NULL;
 }
@@ -233,14 +236,17 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
 struct usb_endpoint_descriptor *
 usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
 {
+       struct usb_host_config *config = dev->actconfig;
        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_host_interface       *alt;
 
-               /* only endpoints in current altseting are active */
-               intf = dev->actconfig->interface[i];
+               /* only endpoints in current altsetting are active */
+               intf = config->interface[i];
                alt = intf->altsetting + intf->act_altsetting;
 
                for (k = 0; k < alt->desc.bNumEndpoints; k++)