···57 !(hcd->driver->flags & HCD_LOCAL_MEM))58 return 0;5960- for (i = 0; i < HCD_BUFFER_POOLS; i++) { 61- if (!(size = pool_max [i]))062 continue;63 snprintf(name, sizeof name, "buffer-%d", size);64 hcd->pool[i] = dma_pool_create(name, hcd->self.controller,···82 */83void hcd_buffer_destroy(struct usb_hcd *hcd)84{85- int i;8687- for (i = 0; i < HCD_BUFFER_POOLS; i++) { 88- struct dma_pool *pool = hcd->pool[i];89 if (pool) {90 dma_pool_destroy(pool);91 hcd->pool[i] = NULL;
···57 !(hcd->driver->flags & HCD_LOCAL_MEM))58 return 0;5960+ for (i = 0; i < HCD_BUFFER_POOLS; i++) {61+ size = pool_max[i];62+ if (!size)63 continue;64 snprintf(name, sizeof name, "buffer-%d", size);65 hcd->pool[i] = dma_pool_create(name, hcd->self.controller,···81 */82void hcd_buffer_destroy(struct usb_hcd *hcd)83{84+ int i;8586+ for (i = 0; i < HCD_BUFFER_POOLS; i++) {87+ struct dma_pool *pool = hcd->pool[i];88 if (pool) {89 dma_pool_destroy(pool);90 hcd->pool[i] = NULL;
+8-6
drivers/usb/core/config.c
···238239 /* Allocate space for the right(?) number of endpoints */240 num_ep = num_ep_orig = alt->desc.bNumEndpoints;241- alt->desc.bNumEndpoints = 0; // Use as a counter242 if (num_ep > USB_MAXENDPOINTS) {243 dev_warn(ddev, "too many endpoints for config %d interface %d "244 "altsetting %d: %d, using maximum allowed: %d\n",···246 num_ep = USB_MAXENDPOINTS;247 }248249- if (num_ep > 0) { /* Can't allocate 0 bytes */0250 len = sizeof(struct usb_host_endpoint) * num_ep;251 alt->endpoint = kzalloc(len, GFP_KERNEL);252 if (!alt->endpoint)···476 return 0;477}478479-// hub-only!! ... and only exported for reset/reinit path.480-// otherwise used internally on disconnect/destroy path0481void usb_destroy_configuration(struct usb_device *dev)482{483 int c, i;···500 kfree(cf->string);501 for (i = 0; i < cf->desc.bNumInterfaces; i++) {502 if (cf->intf_cache[i])503- kref_put(&cf->intf_cache[i]->ref, 504 usb_release_interface_cache);505 }506 }···527 unsigned int cfgno, length;528 unsigned char *buffer;529 unsigned char *bigbuffer;530- struct usb_config_descriptor *desc;531532 cfgno = 0;533 if (dev->authorized == 0) /* Not really an error */
···238239 /* Allocate space for the right(?) number of endpoints */240 num_ep = num_ep_orig = alt->desc.bNumEndpoints;241+ alt->desc.bNumEndpoints = 0; /* Use as a counter */242 if (num_ep > USB_MAXENDPOINTS) {243 dev_warn(ddev, "too many endpoints for config %d interface %d "244 "altsetting %d: %d, using maximum allowed: %d\n",···246 num_ep = USB_MAXENDPOINTS;247 }248249+ if (num_ep > 0) {250+ /* Can't allocate 0 bytes */251 len = sizeof(struct usb_host_endpoint) * num_ep;252 alt->endpoint = kzalloc(len, GFP_KERNEL);253 if (!alt->endpoint)···475 return 0;476}477478+/* hub-only!! ... and only exported for reset/reinit path.479+ * otherwise used internally on disconnect/destroy path480+ */481void usb_destroy_configuration(struct usb_device *dev)482{483 int c, i;···498 kfree(cf->string);499 for (i = 0; i < cf->desc.bNumInterfaces; i++) {500 if (cf->intf_cache[i])501+ kref_put(&cf->intf_cache[i]->ref,502 usb_release_interface_cache);503 }504 }···525 unsigned int cfgno, length;526 unsigned char *buffer;527 unsigned char *bigbuffer;528+ struct usb_config_descriptor *desc;529530 cfgno = 0;531 if (dev->authorized == 0) /* Not really an error */
+16-14
drivers/usb/core/driver.c
···202 intf = to_usb_interface(dev);203 udev = interface_to_usbdev(intf);204205- if (udev->authorized == 0) {206- dev_err(&intf->dev, "Device is not authorized for usage\n");207- return -ENODEV;208- }209210 id = usb_match_id(intf, driver->id_table);211 if (!id)···299 * lock.300 */301int usb_driver_claim_interface(struct usb_driver *driver,302- struct usb_interface *iface, void* priv)303{304 struct device *dev = &iface->dev;305 struct usb_device *udev = interface_to_usbdev(iface);···398 return 0;399400 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&401- (id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass))402 return 0;403404 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&···586 struct usb_device *usb_dev;587588 /* driver is often null here; dev_dbg() would oops */589- pr_debug ("usb %s: uevent\n", dev->bus_id);590591 if (is_usb_device(dev))592 usb_dev = to_usb_device(dev);···596 }597598 if (usb_dev->devnum < 0) {599- pr_debug ("usb %s: already deleted?\n", dev->bus_id);600 return -ENODEV;601 }602 if (!usb_dev->bus) {603- pr_debug ("usb %s: bus removed?\n", dev->bus_id);604 return -ENODEV;605 }606···854 dev_err(&intf->dev, "%s error %d\n",855 "suspend", status);856 } else {857- // FIXME else if there's no suspend method, disconnect...858- // Not possible if auto_pm is set...00859 dev_warn(&intf->dev, "no suspend for driver %s?\n",860 driver->name);861 mark_quiesced(intf);···896 dev_err(&intf->dev, "%s error %d\n",897 "reset_resume", status);898 } else {899- // status = -EOPNOTSUPP;900 dev_warn(&intf->dev, "no %s for driver %s?\n",901 "reset_resume", driver->name);902 }···907 dev_err(&intf->dev, "%s error %d\n",908 "resume", status);909 } else {910- // status = -EOPNOTSUPP;911 dev_warn(&intf->dev, "no %s for driver %s?\n",912 "resume", driver->name);913 }···1177 * so if a root hub's controller is suspended1178 * then we're stuck. */1179 status = usb_resume_device(udev);1180- }1181 } else {11821183 /* Needed for setting udev->dev.power.power_state.event,
···202 intf = to_usb_interface(dev);203 udev = interface_to_usbdev(intf);204205+ if (udev->authorized == 0) {206+ dev_err(&intf->dev, "Device is not authorized for usage\n");207+ return -ENODEV;208+ }209210 id = usb_match_id(intf, driver->id_table);211 if (!id)···299 * lock.300 */301int usb_driver_claim_interface(struct usb_driver *driver,302+ struct usb_interface *iface, void *priv)303{304 struct device *dev = &iface->dev;305 struct usb_device *udev = interface_to_usbdev(iface);···398 return 0;399400 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&401+ (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))402 return 0;403404 if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&···586 struct usb_device *usb_dev;587588 /* driver is often null here; dev_dbg() would oops */589+ pr_debug("usb %s: uevent\n", dev->bus_id);590591 if (is_usb_device(dev))592 usb_dev = to_usb_device(dev);···596 }597598 if (usb_dev->devnum < 0) {599+ pr_debug("usb %s: already deleted?\n", dev->bus_id);600 return -ENODEV;601 }602 if (!usb_dev->bus) {603+ pr_debug("usb %s: bus removed?\n", dev->bus_id);604 return -ENODEV;605 }606···854 dev_err(&intf->dev, "%s error %d\n",855 "suspend", status);856 } else {857+ /*858+ * FIXME else if there's no suspend method, disconnect...859+ * Not possible if auto_pm is set...860+ */861 dev_warn(&intf->dev, "no suspend for driver %s?\n",862 driver->name);863 mark_quiesced(intf);···894 dev_err(&intf->dev, "%s error %d\n",895 "reset_resume", status);896 } else {897+ /* status = -EOPNOTSUPP; */898 dev_warn(&intf->dev, "no %s for driver %s?\n",899 "reset_resume", driver->name);900 }···905 dev_err(&intf->dev, "%s error %d\n",906 "resume", status);907 } else {908+ /* status = -EOPNOTSUPP; */909 dev_warn(&intf->dev, "no %s for driver %s?\n",910 "resume", driver->name);911 }···1175 * so if a root hub's controller is suspended1176 * then we're stuck. */1177 status = usb_resume_device(udev);1178+ }1179 } else {11801181 /* Needed for setting udev->dev.power.power_state.event,
···103 *104 * A pointer to the urb with the incremented reference counter is returned.105 */106-struct urb * usb_get_urb(struct urb *urb)107{108 if (urb)109 kref_get(&urb->kref);···176 * describing that request to the USB subsystem. Request completion will177 * be indicated later, asynchronously, by calling the completion handler.178 * The three types of completion are success, error, and unlink179- * (a software-induced fault, also called "request cancellation"). 180 *181 * URBs may be submitted in interrupt context.182 *···259 * semaphores), or260 * (c) current->state != TASK_RUNNING, this is the case only after261 * you've changed it.262- * 263 * GFP_NOIO is used in the block io path and error handling of storage264 * devices.265 *···288289 if (!urb || urb->hcpriv || !urb->complete)290 return -EINVAL;291- if (!(dev = urb->dev) || dev->state < USB_STATE_DEFAULT)0292 return -ENODEV;293294 /* For now, get the endpoint from the pipe. Eventually drivers···352 max *= mult;353 }354355- if (urb->number_of_packets <= 0) 356 return -EINVAL;357 for (n = 0; n < urb->number_of_packets; n++) {358 len = urb->iso_frame_desc[n].length;359- if (len < 0 || len > max) 360 return -EMSGSIZE;361 urb->iso_frame_desc[n].status = -EXDEV;362 urb->iso_frame_desc[n].actual_length = 0;···421 /* too big? */422 switch (dev->speed) {423 case USB_SPEED_HIGH: /* units are microframes */424- // NOTE usb handles 2^15425 if (urb->interval > (1024 * 8))426 urb->interval = 1024 * 8;427 max = 1024 * 8;···431 if (xfertype == USB_ENDPOINT_XFER_INT) {432 if (urb->interval > 255)433 return -EINVAL;434- // NOTE ohci only handles up to 32435 max = 128;436 } else {437 if (urb->interval > 1024)438 urb->interval = 1024;439- // NOTE usb and ohci handle up to 2^15440 max = 1024;441 }442 break;···575576 spin_lock_irq(&anchor->lock);577 while (!list_empty(&anchor->urb_list)) {578- victim = list_entry(anchor->urb_list.prev, struct urb, anchor_list);0579 /* we must make sure the URB isn't freed before we kill it*/580 usb_get_urb(victim);581 spin_unlock_irq(&anchor->lock);
···103 *104 * A pointer to the urb with the incremented reference counter is returned.105 */106+struct urb *usb_get_urb(struct urb *urb)107{108 if (urb)109 kref_get(&urb->kref);···176 * describing that request to the USB subsystem. Request completion will177 * be indicated later, asynchronously, by calling the completion handler.178 * The three types of completion are success, error, and unlink179+ * (a software-induced fault, also called "request cancellation").180 *181 * URBs may be submitted in interrupt context.182 *···259 * semaphores), or260 * (c) current->state != TASK_RUNNING, this is the case only after261 * you've changed it.262+ *263 * GFP_NOIO is used in the block io path and error handling of storage264 * devices.265 *···288289 if (!urb || urb->hcpriv || !urb->complete)290 return -EINVAL;291+ dev = urb->dev;292+ if ((!dev) || (dev->state < USB_STATE_DEFAULT))293 return -ENODEV;294295 /* For now, get the endpoint from the pipe. Eventually drivers···351 max *= mult;352 }353354+ if (urb->number_of_packets <= 0)355 return -EINVAL;356 for (n = 0; n < urb->number_of_packets; n++) {357 len = urb->iso_frame_desc[n].length;358+ if (len < 0 || len > max)359 return -EMSGSIZE;360 urb->iso_frame_desc[n].status = -EXDEV;361 urb->iso_frame_desc[n].actual_length = 0;···420 /* too big? */421 switch (dev->speed) {422 case USB_SPEED_HIGH: /* units are microframes */423+ /* NOTE usb handles 2^15 */424 if (urb->interval > (1024 * 8))425 urb->interval = 1024 * 8;426 max = 1024 * 8;···430 if (xfertype == USB_ENDPOINT_XFER_INT) {431 if (urb->interval > 255)432 return -EINVAL;433+ /* NOTE ohci only handles up to 32 */434 max = 128;435 } else {436 if (urb->interval > 1024)437 urb->interval = 1024;438+ /* NOTE usb and ohci handle up to 2^15 */439 max = 1024;440 }441 break;···574575 spin_lock_irq(&anchor->lock);576 while (!list_empty(&anchor->urb_list)) {577+ victim = list_entry(anchor->urb_list.prev, struct urb,578+ anchor_list);579 /* we must make sure the URB isn't freed before we kill it*/580 usb_get_urb(victim);581 spin_unlock_irq(&anchor->lock);
+22-29
drivers/usb/core/usb.c
···116 * Don't call this function unless you are bound to the intf interface117 * or you have locked the device!118 */119-struct usb_host_interface *usb_altnum_to_altsetting(const struct usb_interface *intf,120- unsigned int altnum)0121{122 int i;123···135 struct usb_interface *interface;136};137138-static int __find_interface(struct device * dev, void * data)139{140 struct find_interface_arg *arg = data;141 struct usb_interface *intf;···157 * @drv: the driver whose current configuration is considered158 * @minor: the minor number of the desired device159 *160- * This walks the driver device list and returns a pointer to the interface 161 * with the matching minor. Note, this only works for devices that share the162 * USB major number.163 */···273 *274 * This call may not be used in a non-sleeping context.275 */276-struct usb_device *277-usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)278{279 struct usb_device *dev;280 struct usb_hcd *usb_hcd = container_of(bus, struct usb_hcd, self);···470 return -EHOSTUNREACH;471 if (iface) {472 switch (iface->condition) {473- case USB_INTERFACE_BINDING:474 return 0;475- case USB_INTERFACE_BOUND:476 break;477- default:478 return -EINTR;479 }480 }···549 struct list_head *buslist;550 struct usb_bus *bus;551 struct usb_device *dev = NULL;552-553 mutex_lock(&usb_bus_list_lock);554 for (buslist = usb_bus_list.next;555- buslist != &usb_bus_list; 556 buslist = buslist->next) {557 bus = container_of(buslist, struct usb_bus, bus_list);558 if (!bus->root_hub)···594 */595596int __usb_get_extra_descriptor(char *buffer, unsigned size,597- unsigned char type, void **ptr)598{599 struct usb_descriptor_header *header;600···605 printk(KERN_ERR606 "%s: bogus descriptor, type %d length %d\n",607 usbcore_name,608- header->bDescriptorType, 609 header->bLength);610 return -1;611 }···644 *645 * When the buffer is no longer used, free it with usb_buffer_free().646 */647-void *usb_buffer_alloc(648- struct usb_device *dev,649- size_t size,650- gfp_t mem_flags,651- dma_addr_t *dma652-)653{654 if (!dev || !dev->bus)655 return NULL;···664 * been allocated using usb_buffer_alloc(), and the parameters must match665 * those provided in that allocation request.666 */667-void usb_buffer_free(668- struct usb_device *dev,669- size_t size,670- void *addr,671- dma_addr_t dma672-)673{674 if (!dev || !dev->bus)675 return;···713 urb->setup_packet,714 sizeof(struct usb_ctrlrequest),715 DMA_TO_DEVICE);716- // FIXME generic api broken like pci, can't report errors717- // if (urb->transfer_dma == DMA_ADDR_INVALID) return 0;718 } else719 urb->transfer_dma = ~0;720 urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP···836 || !controller->dma_mask)837 return -1;838839- // FIXME generic api broken like pci, can't report errors840 return dma_map_sg(controller, sg, nents,841 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);842}···930 if (retval)931 goto out;932 retval = bus_register(&usb_bus_type);933- if (retval) 934 goto bus_register_failed;935 retval = usb_host_init();936 if (retval)
···116 * Don't call this function unless you are bound to the intf interface117 * or you have locked the device!118 */119+struct usb_host_interface *usb_altnum_to_altsetting(120+ const struct usb_interface *intf,121+ unsigned int altnum)122{123 int i;124···134 struct usb_interface *interface;135};136137+static int __find_interface(struct device *dev, void *data)138{139 struct find_interface_arg *arg = data;140 struct usb_interface *intf;···156 * @drv: the driver whose current configuration is considered157 * @minor: the minor number of the desired device158 *159+ * This walks the driver device list and returns a pointer to the interface160 * with the matching minor. Note, this only works for devices that share the161 * USB major number.162 */···272 *273 * This call may not be used in a non-sleeping context.274 */275+struct usb_device *usb_alloc_dev(struct usb_device *parent,276+ struct usb_bus *bus, unsigned port1)277{278 struct usb_device *dev;279 struct usb_hcd *usb_hcd = container_of(bus, struct usb_hcd, self);···469 return -EHOSTUNREACH;470 if (iface) {471 switch (iface->condition) {472+ case USB_INTERFACE_BINDING:473 return 0;474+ case USB_INTERFACE_BOUND:475 break;476+ default:477 return -EINTR;478 }479 }···548 struct list_head *buslist;549 struct usb_bus *bus;550 struct usb_device *dev = NULL;551+552 mutex_lock(&usb_bus_list_lock);553 for (buslist = usb_bus_list.next;554+ buslist != &usb_bus_list;555 buslist = buslist->next) {556 bus = container_of(buslist, struct usb_bus, bus_list);557 if (!bus->root_hub)···593 */594595int __usb_get_extra_descriptor(char *buffer, unsigned size,596+ unsigned char type, void **ptr)597{598 struct usb_descriptor_header *header;599···604 printk(KERN_ERR605 "%s: bogus descriptor, type %d length %d\n",606 usbcore_name,607+ header->bDescriptorType,608 header->bLength);609 return -1;610 }···643 *644 * When the buffer is no longer used, free it with usb_buffer_free().645 */646+void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags,647+ dma_addr_t *dma)0000648{649 if (!dev || !dev->bus)650 return NULL;···667 * been allocated using usb_buffer_alloc(), and the parameters must match668 * those provided in that allocation request.669 */670+void usb_buffer_free(struct usb_device *dev, size_t size, void *addr,671+ dma_addr_t dma)0000672{673 if (!dev || !dev->bus)674 return;···720 urb->setup_packet,721 sizeof(struct usb_ctrlrequest),722 DMA_TO_DEVICE);723+ /* FIXME generic api broken like pci, can't report errors */724+ /* if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; */725 } else726 urb->transfer_dma = ~0;727 urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP···843 || !controller->dma_mask)844 return -1;845846+ /* FIXME generic api broken like pci, can't report errors */847 return dma_map_sg(controller, sg, nents,848 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);849}···937 if (retval)938 goto out;939 retval = bus_register(&usb_bus_type);940+ if (retval)941 goto bus_register_failed;942 retval = usb_host_init();943 if (retval)