From 78e5ed076c2e87079611c025e899d605f5b8a298 Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Sun, 8 Sep 2013 02:12:26 -0400 Subject: [PATCH] modify kernel to build with ctf, add usb_find_device_by_name function Change-Id: I441e00915db7b158627ae2e104938390332bc6aa --- .../linux/linux-2.6/drivers/net/ctf/Makefile | 4 +- .../linux/linux-2.6/drivers/usb/core/usb.c | 65 ++++++++++++++++++++++ .../src-rt-6.x/linux/linux-2.6/include/linux/usb.h | 1 + 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/release/src-rt-6.x/linux/linux-2.6/drivers/net/ctf/Makefile b/release/src-rt-6.x/linux/linux-2.6/drivers/net/ctf/Makefile index cca9fbf5c3..745c61ffb5 100644 --- a/release/src-rt-6.x/linux/linux-2.6/drivers/net/ctf/Makefile +++ b/release/src-rt-6.x/linux/linux-2.6/drivers/net/ctf/Makefile @@ -20,13 +20,13 @@ obj-${CONFIG_BCM_CTF} := ctf.o -CTFSRC := ../../../../../router/ctf +CTFSRC := ../../../../../ctf CTFOBJ := $(CTFSRC)/hndctf.o $(CTFSRC)/hndctf_linux.o SYMOBJ := $(CTFSRC)/hndctf.o # Search for sources under src/router/ctf ifneq (,$(wildcard $(src)/$(CTFSRC)/*.c)) - EXTRA_CFLAGS += -I$(src)/$(CTFSRC)/../../router/ctf + EXTRA_CFLAGS += -I$(src)/$(CTFSRC)/../../ctf ctf-objs := $(CTFOBJ) ctf_ksyms.o else ctf-objs := $(CTFSRC)/linux/ctf.o diff --git a/release/src-rt-6.x/linux/linux-2.6/drivers/usb/core/usb.c b/release/src-rt-6.x/linux/linux-2.6/drivers/usb/core/usb.c index f18c2c0fe7..a8d5e09569 100644 --- a/release/src-rt-6.x/linux/linux-2.6/drivers/usb/core/usb.c +++ b/release/src-rt-6.x/linux/linux-2.6/drivers/usb/core/usb.c @@ -516,6 +516,71 @@ exit: return dev; } +static struct usb_device *match_device_name(struct usb_device *dev, + const char *name) +{ + struct usb_device *ret_dev = NULL; + int child; + + dev_dbg(&dev->dev, "check for name %s ...\n", name); + + /* see if this device matches */ + if (strcmp(dev_name(&dev->dev), name) == 0 ) { + dev_dbg(&dev->dev, "matched this device!\n"); + ret_dev = usb_get_dev(dev); + goto exit; + } + + /* look through all of the children of this device */ + for (child = 0; child < dev->maxchild; ++child) { + if (dev->children[child]) { + usb_lock_device(dev->children[child]); + ret_dev = match_device_name(dev->children[child], name); + usb_unlock_device(dev->children[child]); + if (ret_dev) + goto exit; + } + } +exit: + return ret_dev; +} + +/** + * usb_find_device_by_name - find a specific usb device in the system + * @name: the name of the device to find + * + * Returns a pointer to a struct usb_device if such a specified usb + * device is present in the system currently. The usage count of the + * device will be incremented if a device is found. Make sure to call + * usb_put_dev() when the caller is finished with the device. + * + * If a device with the specified bus id is not found, NULL is returned. + */ +struct usb_device *usb_find_device_by_name(const char *name) +{ + struct list_head *buslist; + struct usb_bus *bus; + struct usb_device *dev = NULL; + + mutex_lock(&usb_bus_list_lock); + for (buslist = usb_bus_list.next; + buslist != &usb_bus_list; + buslist = buslist->next) { + bus = container_of(buslist, struct usb_bus, bus_list); + if (!bus->root_hub) + continue; + usb_lock_device(bus->root_hub); + dev = match_device_name(bus->root_hub, name); + usb_unlock_device(bus->root_hub); + if (dev) + goto exit; + } +exit: + mutex_unlock(&usb_bus_list_lock); + return dev; +} +EXPORT_SYMBOL_GPL(usb_find_device_by_name); + /** * usb_get_current_frame_number - return current bus frame number * @dev: the device whose bus is being queried diff --git a/release/src-rt-6.x/linux/linux-2.6/include/linux/usb.h b/release/src-rt-6.x/linux/linux-2.6/include/linux/usb.h index c8c027fe97..d925dcc4ba 100644 --- a/release/src-rt-6.x/linux/linux-2.6/include/linux/usb.h +++ b/release/src-rt-6.x/linux/linux-2.6/include/linux/usb.h @@ -459,6 +459,7 @@ extern int usb_reset_device(struct usb_device *dev); extern void usb_queue_reset_device(struct usb_interface *dev); extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id); +extern struct usb_device *usb_find_device_by_name(const char *name); /* USB autosuspend and autoresume */ #ifdef CONFIG_USB_SUSPEND -- 2.11.4.GIT