Commit 695794ae authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

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: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 93562b53
...@@ -302,6 +302,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device); ...@@ -302,6 +302,7 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
/** /**
* class_find_device - device iterator for locating a particular device * class_find_device - device iterator for locating a particular device
* @class: the class we're iterating * @class: the class we're iterating
* @start: Device to begin with
* @data: data for the match function * @data: data for the match function
* @match: function to check device * @match: function to check device
* *
...@@ -319,8 +320,9 @@ EXPORT_SYMBOL_GPL(class_for_each_device); ...@@ -319,8 +320,9 @@ EXPORT_SYMBOL_GPL(class_for_each_device);
* re-acquired in @match, otherwise it will self-deadlocking. For * re-acquired in @match, otherwise it will self-deadlocking. For
* example, calls to add or remove class members would be verboten. * 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,
int (*match)(struct device *, void *)) void *data,
int (*match)(struct device *, void *))
{ {
struct device *dev; struct device *dev;
int found = 0; int found = 0;
...@@ -330,15 +332,17 @@ struct device *class_find_device(struct class *class, void *data, ...@@ -330,15 +332,17 @@ struct device *class_find_device(struct class *class, void *data,
down(&class->sem); down(&class->sem);
list_for_each_entry(dev, &class->devices, node) { list_for_each_entry(dev, &class->devices, node) {
if (start) {
if (start == dev)
start = NULL;
continue;
}
dev = get_device(dev); dev = get_device(dev);
if (dev) { if (match(dev, data)) {
if (match(dev, data)) { found = 1;
found = 1;
break;
} else
put_device(dev);
} else
break; break;
} else
put_device(dev);
} }
up(&class->sem); up(&class->sem);
......
...@@ -1289,7 +1289,7 @@ void device_destroy(struct class *class, dev_t devt) ...@@ -1289,7 +1289,7 @@ void device_destroy(struct class *class, dev_t devt)
{ {
struct device *dev; struct device *dev;
dev = class_find_device(class, &devt, __match_devt); dev = class_find_device(class, NULL, &devt, __match_devt);
if (dev) { if (dev) {
put_device(dev); put_device(dev);
device_unregister(dev); device_unregister(dev);
......
...@@ -754,7 +754,8 @@ static void nodemgr_remove_uds(struct node_entry *ne) ...@@ -754,7 +754,8 @@ static void nodemgr_remove_uds(struct node_entry *ne)
*/ */
mutex_lock(&nodemgr_serialize_remove_uds); mutex_lock(&nodemgr_serialize_remove_uds);
for (;;) { for (;;) {
dev = class_find_device(&nodemgr_ud_class, ne, __match_ne); dev = class_find_device(&nodemgr_ud_class, NULL, ne,
__match_ne);
if (!dev) if (!dev)
break; break;
ud = container_of(dev, struct unit_directory, unit_dev); ud = container_of(dev, struct unit_directory, unit_dev);
...@@ -901,7 +902,8 @@ static struct node_entry *find_entry_by_guid(u64 guid) ...@@ -901,7 +902,8 @@ static struct node_entry *find_entry_by_guid(u64 guid)
struct device *dev; struct device *dev;
struct node_entry *ne; 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) if (!dev)
return NULL; return NULL;
ne = container_of(dev, struct node_entry, node_dev); 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, ...@@ -940,7 +942,8 @@ static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
param.host = host; param.host = host;
param.nodeid = nodeid; 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) if (!dev)
return NULL; return NULL;
ne = container_of(dev, struct node_entry, node_dev); ne = container_of(dev, struct node_entry, node_dev);
......
...@@ -345,7 +345,7 @@ struct rtc_device *rtc_class_open(char *name) ...@@ -345,7 +345,7 @@ struct rtc_device *rtc_class_open(char *name)
struct device *dev; struct device *dev;
struct rtc_device *rtc = NULL; 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) if (dev)
rtc = to_rtc_device(dev); rtc = to_rtc_device(dev);
......
...@@ -466,7 +466,8 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum) ...@@ -466,7 +466,8 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
struct device *cdev; struct device *cdev;
struct Scsi_Host *shost = ERR_PTR(-ENXIO); 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) { if (cdev) {
shost = scsi_host_get(class_to_shost(cdev)); shost = scsi_host_get(class_to_shost(cdev));
put_device(cdev); put_device(cdev);
......
...@@ -170,7 +170,7 @@ iscsi_create_endpoint(int dd_size) ...@@ -170,7 +170,7 @@ iscsi_create_endpoint(int dd_size)
int err; int err;
for (id = 1; id < ISCSI_MAX_EPID; id++) { 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); iscsi_match_epid);
if (!dev) if (!dev)
break; break;
...@@ -222,7 +222,7 @@ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle) ...@@ -222,7 +222,7 @@ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
struct iscsi_endpoint *ep; struct iscsi_endpoint *ep;
struct device *dev; struct device *dev;
dev = class_find_device(&iscsi_endpoint_class, &handle, dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
iscsi_match_epid); iscsi_match_epid);
if (!dev) if (!dev)
return NULL; return NULL;
......
...@@ -502,7 +502,7 @@ struct spi_master *spi_busnum_to_master(u16 bus_num) ...@@ -502,7 +502,7 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)
struct device *dev; struct device *dev;
struct spi_master *master = NULL; 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); __spi_master_match);
if (dev) if (dev)
master = container_of(dev, struct spi_master, dev); master = container_of(dev, struct spi_master, dev);
......
...@@ -213,7 +213,8 @@ extern void class_unregister(struct class *class); ...@@ -213,7 +213,8 @@ extern void class_unregister(struct class *class);
extern int class_for_each_device(struct class *class, struct device *start, extern int class_for_each_device(struct class *class, struct device *start,
void *data, void *data,
int (*fn)(struct device *dev, 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 *)); int (*match)(struct device *, void *));
struct class_attribute { struct class_attribute {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment