From 6e8339b971ff30c5150acfdbef9a04d8c2362f6d Mon Sep 17 00:00:00 2001 From: Alan Stern Date: Mon, 26 Jan 2004 01:11:51 -0800 Subject: [PATCH] [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). --- drivers/usb/core/usb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 05a7a9f8fa551..89d18fa37d0b2 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -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++) -- 2.53.0