diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2008-01-27 13:29:20 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-01-27 18:01:39 -0500 |
commit | 1f9ffc049d7a88c8489b883b6fc0a25185062002 (patch) | |
tree | 0dddb114d2de5f380ab055c039da0549adb42b12 /drivers/base/bus.c | |
parent | 123ca9575b1f5342c05a4b84d6af8ba7587c2981 (diff) |
Driver core: add bus_find_device_by_name function
The driver core, and some other parts of the kernel just want to find a
device based on a name for a specific bus. Give them a simple wrapper
to prevent them from having to always roll their own.
This will be used in the PPC patch later in this series.
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r-- | drivers/base/bus.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index f484495b2ad..055989e9479 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -163,15 +163,6 @@ static struct kset *bus_kset; | |||
163 | 163 | ||
164 | #ifdef CONFIG_HOTPLUG | 164 | #ifdef CONFIG_HOTPLUG |
165 | /* Manually detach a device from its associated driver. */ | 165 | /* Manually detach a device from its associated driver. */ |
166 | static int driver_helper(struct device *dev, void *data) | ||
167 | { | ||
168 | const char *name = data; | ||
169 | |||
170 | if (strcmp(name, dev->bus_id) == 0) | ||
171 | return 1; | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | static ssize_t driver_unbind(struct device_driver *drv, | 166 | static ssize_t driver_unbind(struct device_driver *drv, |
176 | const char *buf, size_t count) | 167 | const char *buf, size_t count) |
177 | { | 168 | { |
@@ -179,7 +170,7 @@ static ssize_t driver_unbind(struct device_driver *drv, | |||
179 | struct device *dev; | 170 | struct device *dev; |
180 | int err = -ENODEV; | 171 | int err = -ENODEV; |
181 | 172 | ||
182 | dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); | 173 | dev = bus_find_device_by_name(bus, NULL, buf); |
183 | if (dev && dev->driver == drv) { | 174 | if (dev && dev->driver == drv) { |
184 | if (dev->parent) /* Needed for USB */ | 175 | if (dev->parent) /* Needed for USB */ |
185 | down(&dev->parent->sem); | 176 | down(&dev->parent->sem); |
@@ -206,7 +197,7 @@ static ssize_t driver_bind(struct device_driver *drv, | |||
206 | struct device *dev; | 197 | struct device *dev; |
207 | int err = -ENODEV; | 198 | int err = -ENODEV; |
208 | 199 | ||
209 | dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); | 200 | dev = bus_find_device_by_name(bus, NULL, buf); |
210 | if (dev && dev->driver == NULL) { | 201 | if (dev && dev->driver == NULL) { |
211 | if (dev->parent) /* Needed for USB */ | 202 | if (dev->parent) /* Needed for USB */ |
212 | down(&dev->parent->sem); | 203 | down(&dev->parent->sem); |
@@ -250,7 +241,7 @@ static ssize_t store_drivers_probe(struct bus_type *bus, | |||
250 | { | 241 | { |
251 | struct device *dev; | 242 | struct device *dev; |
252 | 243 | ||
253 | dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); | 244 | dev = bus_find_device_by_name(bus, NULL, buf); |
254 | if (!dev) | 245 | if (!dev) |
255 | return -ENODEV; | 246 | return -ENODEV; |
256 | if (bus_rescan_devices_helper(dev, NULL) != 0) | 247 | if (bus_rescan_devices_helper(dev, NULL) != 0) |
@@ -338,6 +329,32 @@ struct device *bus_find_device(struct bus_type *bus, | |||
338 | } | 329 | } |
339 | EXPORT_SYMBOL_GPL(bus_find_device); | 330 | EXPORT_SYMBOL_GPL(bus_find_device); |
340 | 331 | ||
332 | static int match_name(struct device *dev, void *data) | ||
333 | { | ||
334 | const char *name = data; | ||
335 | |||
336 | if (strcmp(name, dev->bus_id) == 0) | ||
337 | return 1; | ||
338 | return 0; | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * bus_find_device_by_name - device iterator for locating a particular device of a specific name | ||
343 | * @bus: bus type | ||
344 | * @start: Device to begin with | ||
345 | * @name: name of the device to match | ||
346 | * | ||
347 | * This is similar to the bus_find_device() function above, but it handles | ||
348 | * searching by a name automatically, no need to write another strcmp matching | ||
349 | * function. | ||
350 | */ | ||
351 | struct device *bus_find_device_by_name(struct bus_type *bus, | ||
352 | struct device *start, const char *name) | ||
353 | { | ||
354 | return bus_find_device(bus, start, (void *)name, match_name); | ||
355 | } | ||
356 | EXPORT_SYMBOL_GPL(bus_find_device_by_name); | ||
357 | |||
341 | static struct device_driver *next_driver(struct klist_iter *i) | 358 | static struct device_driver *next_driver(struct klist_iter *i) |
342 | { | 359 | { |
343 | struct klist_node *n = klist_next(i); | 360 | struct klist_node *n = klist_next(i); |