Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+13 −9
Original line number Original line Diff line number Diff line
@@ -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,7 +320,8 @@ 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,
				 void *data,
				 int (*match)(struct device *, void *))
				 int (*match)(struct device *, void *))
{
{
	struct device *dev;
	struct device *dev;
@@ -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;
			break;
		} else
		} else
			put_device(dev);
			put_device(dev);
		} else
			break;
	}
	}
	up(&class->sem);
	up(&class->sem);


+1 −1
Original line number Original line Diff line number Diff line
@@ -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);
+6 −3
Original line number Original line Diff line number Diff line
@@ -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)
	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,
	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);
+1 −1
Original line number Original line Diff line number Diff line
@@ -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);


+2 −1
Original line number Original line Diff line number Diff line
@@ -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);
Loading