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

Commit 93562b53 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

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



This mirrors the functionality that driver_for_each_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 4e106739
Loading
Loading
Loading
Loading
+13 −8
Original line number Original line Diff line number Diff line
@@ -256,11 +256,14 @@ char *make_class_name(const char *name, struct kobject *kobj)
/**
/**
 * class_for_each_device - device iterator
 * class_for_each_device - device iterator
 * @class: the class we're iterating
 * @class: the class we're iterating
 * @start: the device to start with in the list, if any.
 * @data: data for the callback
 * @data: data for the callback
 * @fn: function to be called for each device
 * @fn: function to be called for each device
 *
 *
 * Iterate over @class's list of devices, and call @fn for each,
 * Iterate over @class's list of devices, and call @fn for each,
 * passing it @data.
 * passing it @data.  If @start is set, the list iteration will start
 * there, otherwise if it is NULL, the iteration starts at the
 * beginning of the list.
 *
 *
 * We check the return of @fn each time. If it returns anything
 * We check the return of @fn each time. If it returns anything
 * other than 0, we break out and return that value.
 * other than 0, we break out and return that value.
@@ -269,8 +272,8 @@ char *make_class_name(const char *name, struct kobject *kobj)
 * re-acquired in @fn, otherwise it will self-deadlocking. For
 * re-acquired in @fn, 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.
 */
 */
int class_for_each_device(struct class *class, void *data,
int class_for_each_device(struct class *class, struct device *start,
			   int (*fn)(struct device *, void *))
			  void *data, int (*fn)(struct device *, void *))
{
{
	struct device *dev;
	struct device *dev;
	int error = 0;
	int error = 0;
@@ -279,12 +282,14 @@ int class_for_each_device(struct class *class, void *data,
		return -EINVAL;
		return -EINVAL;
	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) {
		error = fn(dev, data);
		error = fn(dev, data);
		put_device(dev);
		put_device(dev);
		} else
			error = -ENODEV;
		if (error)
		if (error)
			break;
			break;
	}
	}
+4 −2
Original line number Original line Diff line number Diff line
@@ -722,7 +722,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)


	INIT_LIST_HEAD(&driver->clients);
	INIT_LIST_HEAD(&driver->clients);
	/* Walk the adapters that are already present */
	/* Walk the adapters that are already present */
	class_for_each_device(&i2c_adapter_class, driver, __attach_adapter);
	class_for_each_device(&i2c_adapter_class, NULL, driver,
			      __attach_adapter);


	mutex_unlock(&core_lock);
	mutex_unlock(&core_lock);
	return 0;
	return 0;
@@ -782,7 +783,8 @@ void i2c_del_driver(struct i2c_driver *driver)
{
{
	mutex_lock(&core_lock);
	mutex_lock(&core_lock);


	class_for_each_device(&i2c_adapter_class, driver, __detach_adapter);
	class_for_each_device(&i2c_adapter_class, NULL, driver,
			      __detach_adapter);


	driver_unregister(&driver->driver);
	driver_unregister(&driver->driver);
	pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
	pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
+9 −5
Original line number Original line Diff line number Diff line
@@ -1453,7 +1453,8 @@ static void nodemgr_suspend_ne(struct node_entry *ne)
	ne->in_limbo = 1;
	ne->in_limbo = 1;
	WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
	WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));


	class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_suspend);
	class_for_each_device(&nodemgr_ud_class, NULL, ne,
			      __nodemgr_driver_suspend);
}
}




@@ -1462,7 +1463,8 @@ static void nodemgr_resume_ne(struct node_entry *ne)
	ne->in_limbo = 0;
	ne->in_limbo = 0;
	device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
	device_remove_file(&ne->device, &dev_attr_ne_in_limbo);


	class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_resume);
	class_for_each_device(&nodemgr_ud_class, NULL, ne,
			      __nodemgr_driver_resume);
	HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]",
	HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]",
		   NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
		   NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
}
}
@@ -1498,7 +1500,8 @@ static int __nodemgr_update_pdrv(struct device *dev, void *data)


static void nodemgr_update_pdrv(struct node_entry *ne)
static void nodemgr_update_pdrv(struct node_entry *ne)
{
{
	class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_update_pdrv);
	class_for_each_device(&nodemgr_ud_class, NULL, ne,
			      __nodemgr_update_pdrv);
}
}




@@ -1591,7 +1594,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
	 * while probes are time-consuming. (Well, those probes need some
	 * while probes are time-consuming. (Well, those probes need some
	 * improvement...) */
	 * improvement...) */


	class_for_each_device(&nodemgr_ne_class, &param, __nodemgr_node_probe);
	class_for_each_device(&nodemgr_ne_class, NULL, &param,
			      __nodemgr_node_probe);


	/* If we had a bus reset while we were scanning the bus, it is
	/* If we had a bus reset while we were scanning the bus, it is
	 * possible that we did not probe all nodes.  In that case, we
	 * possible that we did not probe all nodes.  In that case, we
@@ -1826,7 +1830,7 @@ int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))


	hip.cb = cb;
	hip.cb = cb;
	hip.data = data;
	hip.data = data;
	error = class_for_each_device(&hpsb_host_class, &hip,
	error = class_for_each_device(&hpsb_host_class, NULL, &hip,
				      __nodemgr_for_each_host);
				      __nodemgr_for_each_host);


	return error;
	return error;
+1 −1
Original line number Original line Diff line number Diff line
@@ -78,7 +78,7 @@ static void find_main_battery(void)
	main_battery = NULL;
	main_battery = NULL;
	bp.main = main_battery;
	bp.main = main_battery;


	error = class_for_each_device(power_supply_class, &bp,
	error = class_for_each_device(power_supply_class, NULL, &bp,
				      __find_main_battery);
				      __find_main_battery);
	if (error) {
	if (error) {
		main_battery = bp.main;
		main_battery = bp.main;
+2 −2
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ static void power_supply_changed_work(struct work_struct *work)


	dev_dbg(psy->dev, "%s\n", __func__);
	dev_dbg(psy->dev, "%s\n", __func__);


	class_for_each_device(power_supply_class, psy,
	class_for_each_device(power_supply_class, NULL, psy,
			      __power_supply_changed_work);
			      __power_supply_changed_work);


	power_supply_update_leds(psy);
	power_supply_update_leds(psy);
@@ -79,7 +79,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
{
{
	int error;
	int error;


	error = class_for_each_device(power_supply_class, psy,
	error = class_for_each_device(power_supply_class, NULL, psy,
				      __power_supply_am_i_supplied);
				      __power_supply_am_i_supplied);


	dev_dbg(psy->dev, "%s %d\n", __func__, error);
	dev_dbg(psy->dev, "%s %d\n", __func__, error);
Loading