Driver Core: add ability for class_find_device to start in middle of list

This mirrors the functionality that driver_find_device has as well.

We add a start variable, and all callers of the function are fixed up at
the same time.

The block layer will be using this new functionality in a follow-on
patch.


Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Greg Kroah-Hartman 2008-05-22 17:21:08 -04:00
parent 93562b5376
commit 695794ae0c
8 changed files with 28 additions and 19 deletions

View File

@ -302,6 +302,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
/**
* class_find_device - device iterator for locating a particular device
* @class: the class we're iterating
* @start: Device to begin with
* @data: data for the match function
* @match: function to check device
*
@ -319,7 +320,8 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
* re-acquired in @match, otherwise it will self-deadlocking. For
* example, calls to add or remove class members would be verboten.
*/
struct device *class_find_device(struct class *class, void *data,
struct device *class_find_device(struct class *class, struct device *start,
void *data,
int (*match)(struct device *, void *))
{
struct device *dev;
@ -330,15 +332,17 @@ struct device *class_find_device(struct class *class, void *data,
down(&class->sem);
list_for_each_entry(dev, &class->devices, node) {
if (start) {
if (start == dev)
start = NULL;
continue;
}
dev = get_device(dev);
if (dev) {
if (match(dev, data)) {
found = 1;
break;
} else
put_device(dev);
} else
break;
}
up(&class->sem);

View File

@ -1289,7 +1289,7 @@ void device_destroy(struct class *class, dev_t devt)
{
struct device *dev;
dev = class_find_device(class, &devt, __match_devt);
dev = class_find_device(class, NULL, &devt, __match_devt);
if (dev) {
put_device(dev);
device_unregister(dev);

View File

@ -754,7 +754,8 @@ static void nodemgr_remove_uds(struct node_entry *ne)
*/
mutex_lock(&nodemgr_serialize_remove_uds);
for (;;) {
dev = class_find_device(&nodemgr_ud_class, ne, __match_ne);
dev = class_find_device(&nodemgr_ud_class, NULL, ne,
__match_ne);
if (!dev)
break;
ud = container_of(dev, struct unit_directory, unit_dev);
@ -901,7 +902,8 @@ static struct node_entry *find_entry_by_guid(u64 guid)
struct device *dev;
struct node_entry *ne;
dev = class_find_device(&nodemgr_ne_class, &guid, __match_ne_guid);
dev = class_find_device(&nodemgr_ne_class, NULL, &guid,
__match_ne_guid);
if (!dev)
return NULL;
ne = container_of(dev, struct node_entry, node_dev);
@ -940,7 +942,8 @@ static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
param.host = host;
param.nodeid = nodeid;
dev = class_find_device(&nodemgr_ne_class, &param, __match_ne_nodeid);
dev = class_find_device(&nodemgr_ne_class, NULL, &param,
__match_ne_nodeid);
if (!dev)
return NULL;
ne = container_of(dev, struct node_entry, node_dev);

View File

@ -345,7 +345,7 @@ struct rtc_device *rtc_class_open(char *name)
struct device *dev;
struct rtc_device *rtc = NULL;
dev = class_find_device(rtc_class, name, __rtc_match);
dev = class_find_device(rtc_class, NULL, name, __rtc_match);
if (dev)
rtc = to_rtc_device(dev);

View File

@ -466,7 +466,8 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
struct device *cdev;
struct Scsi_Host *shost = ERR_PTR(-ENXIO);
cdev = class_find_device(&shost_class, &hostnum, __scsi_host_match);
cdev = class_find_device(&shost_class, NULL, &hostnum,
__scsi_host_match);
if (cdev) {
shost = scsi_host_get(class_to_shost(cdev));
put_device(cdev);

View File

@ -170,7 +170,7 @@ iscsi_create_endpoint(int dd_size)
int err;
for (id = 1; id < ISCSI_MAX_EPID; id++) {
dev = class_find_device(&iscsi_endpoint_class, &id,
dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
iscsi_match_epid);
if (!dev)
break;
@ -222,7 +222,7 @@ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
struct iscsi_endpoint *ep;
struct device *dev;
dev = class_find_device(&iscsi_endpoint_class, &handle,
dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
iscsi_match_epid);
if (!dev)
return NULL;

View File

@ -502,7 +502,7 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)
struct device *dev;
struct spi_master *master = NULL;
dev = class_find_device(&spi_master_class, &bus_num,
dev = class_find_device(&spi_master_class, NULL, &bus_num,
__spi_master_match);
if (dev)
master = container_of(dev, struct spi_master, dev);

View File

@ -213,7 +213,8 @@ extern void class_unregister(struct class *class);
extern int class_for_each_device(struct class *class, struct device *start,
void *data,
int (*fn)(struct device *dev, void *data));
extern struct device *class_find_device(struct class *class, void *data,
extern struct device *class_find_device(struct class *class,
struct device *start, void *data,
int (*match)(struct device *, void *));
struct class_attribute {