Ticket #9239: 310-usb-add-usb_find_device_by_name.patch

File 310-usb-add-usb_find_device_by_name.patch, 2.4 KB (added by Frex, 7 years ago)

usb_find_device_by_name for kernel 2.6.32/backfire from changeset 26015

  • drivers/usb/core/usb.c

    a b exit: 
    651651        return dev; 
    652652} 
    653653 
     654static struct usb_device *match_device_name(struct usb_device *dev, 
     655                                            const char *name) 
     656{ 
     657        struct usb_device *ret_dev = NULL; 
     658        int child; 
     659 
     660        dev_dbg(&dev->dev, "check for name %s ...\n", name); 
     661 
     662        /* see if this device matches */ 
     663        if (strcmp(dev_name(&dev->dev), name) == 0 ) { 
     664                dev_dbg(&dev->dev, "matched this device!\n"); 
     665                ret_dev = usb_get_dev(dev); 
     666                goto exit; 
     667        } 
     668 
     669        /* look through all of the children of this device */ 
     670        for (child = 0; child < dev->maxchild; ++child) { 
     671                if (dev->children[child]) { 
     672                        usb_lock_device(dev->children[child]); 
     673                        ret_dev = match_device_name(dev->children[child], name); 
     674                        usb_unlock_device(dev->children[child]); 
     675                        if (ret_dev) 
     676                                goto exit; 
     677                } 
     678        } 
     679exit: 
     680        return ret_dev; 
     681} 
     682 
     683/** 
     684 * usb_find_device_by_name - find a specific usb device in the system 
     685 * @name: the name of the device to find 
     686 * 
     687 * Returns a pointer to a struct usb_device if such a specified usb 
     688 * device is present in the system currently.  The usage count of the 
     689 * device will be incremented if a device is found.  Make sure to call 
     690 * usb_put_dev() when the caller is finished with the device. 
     691 * 
     692 * If a device with the specified bus id is not found, NULL is returned. 
     693 */ 
     694struct usb_device *usb_find_device_by_name(const char *name) 
     695{ 
     696        struct list_head *buslist; 
     697        struct usb_bus *bus; 
     698        struct usb_device *dev = NULL; 
     699 
     700        mutex_lock(&usb_bus_list_lock); 
     701        for (buslist = usb_bus_list.next; 
     702             buslist != &usb_bus_list; 
     703             buslist = buslist->next) { 
     704                bus = container_of(buslist, struct usb_bus, bus_list); 
     705                if (!bus->root_hub) 
     706                        continue; 
     707                usb_lock_device(bus->root_hub); 
     708                dev = match_device_name(bus->root_hub, name); 
     709                usb_unlock_device(bus->root_hub); 
     710                if (dev) 
     711                        goto exit; 
     712        } 
     713exit: 
     714        mutex_unlock(&usb_bus_list_lock); 
     715        return dev; 
     716} 
     717EXPORT_SYMBOL_GPL(usb_find_device_by_name); 
     718 
    654719/** 
    655720 * usb_get_current_frame_number - return current bus frame number 
    656721 * @dev: the device whose bus is being queried 
  • include/linux/usb.h

    a b extern int usb_reset_device(struct usb_d 
    540540extern void usb_queue_reset_device(struct usb_interface *dev); 
    541541 
    542542extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id); 
     543extern struct usb_device *usb_find_device_by_name(const char *name); 
    543544 
    544545/* USB autosuspend and autoresume */ 
    545546#ifdef CONFIG_USB_SUSPEND