]> err.no Git - linux-2.6/commitdiff
Driver Core: add ability for class_find_device to start in middle of list
authorGreg Kroah-Hartman <gregkh@suse.de>
Thu, 22 May 2008 21:21:08 +0000 (17:21 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 22 Jul 2008 04:54:47 +0000 (21:54 -0700)
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>
drivers/base/class.c
drivers/base/core.c
drivers/ieee1394/nodemgr.c
drivers/rtc/interface.c
drivers/scsi/hosts.c
drivers/scsi/scsi_transport_iscsi.c
drivers/spi/spi.c
include/linux/device.h

index 2eb7048003a803fd25b57ce2a7be3a444ad94d89..3918d0e432d447565c6bfbfac09ab1d6db7e35c9 100644 (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,8 +320,9 @@ 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,
-                                  int (*match)(struct device *, void *))
+struct device *class_find_device(struct class *class, struct device *start,
+                                void *data,
+                                int (*match)(struct device *, void *))
 {
        struct device *dev;
        int found = 0;
@@ -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
+               if (match(dev, data)) {
+                       found = 1;
                        break;
+               } else
+                       put_device(dev);
        }
        up(&class->sem);
 
index 9ae28aa709d5f8044c65d4ef783e682e818ff241..9f05de6f80b5fd7b8bd3f6bb66bc48eaee60ff8a 100644 (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);
index 47c0d85e0f32126bfdb65e92eb53e20242a0c7c4..994a21e5a0aa7e6d929e94b82f0f8f99efe5b72f 100644 (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);
index 58b7336640ff7a1559263798f46e9d7912f09088..d397fa5f3a91ab650f890aef8d1e59fc5d3005b8 100644 (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);
 
index 35cd892dce04f899336a49c21228fe36984b5155..78dad28b70d5e346a4365ed7b05fca5a20d78a9a 100644 (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);
index 3af7cbcc5c5d7c6f93822a2e7e29f15f17a7df13..06748f318cd57f5c86b0495a4ac2330b9f3378a6 100644 (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;
index 1ad12afc6ba0ace916c817c571b265dc49cc1398..1771b2456bfaf8f60ab3d0fdfafdd443813b3138 100644 (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);
index 6d5b351b29c9975bf7f78a7cd45337313a4cb2cd..c1f72984875fb7b8f19b3c726abf999a3e5ccb70 100644 (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 {