From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>, Kay Sievers <kay.sievers@vrfy.org>
Subject: [PATCH 31/79] Driver Core: add ability for class_for_each_device to start in middle of list
Date: Mon, 21 Jul 2008 22:18:55 -0700 [thread overview]
Message-ID: <1216703983-21448-31-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <20080722051805.GA17373@suse.de>
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: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/base/class.c | 21 +++++++++++++--------
drivers/i2c/i2c-core.c | 6 ++++--
drivers/ieee1394/nodemgr.c | 14 +++++++++-----
drivers/power/apm_power.c | 2 +-
drivers/power/power_supply_core.c | 4 ++--
include/linux/device.h | 3 ++-
6 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 71ce3ff..2eb7048 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -256,11 +256,14 @@ char *make_class_name(const char *name, struct kobject *kobj)
/**
* class_for_each_device - device iterator
* @class: the class we're iterating
+ * @start: the device to start with in the list, if any.
* @data: data for the callback
* @fn: function to be called for each device
*
* 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
* 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
* example, calls to add or remove class members would be verboten.
*/
-int class_for_each_device(struct class *class, void *data,
- int (*fn)(struct device *, void *))
+int class_for_each_device(struct class *class, struct device *start,
+ void *data, int (*fn)(struct device *, void *))
{
struct device *dev;
int error = 0;
@@ -279,12 +282,14 @@ int class_for_each_device(struct class *class, void *data,
return -EINVAL;
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) {
- error = fn(dev, data);
- put_device(dev);
- } else
- error = -ENODEV;
+ error = fn(dev, data);
+ put_device(dev);
if (error)
break;
}
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7608df8..7bf38c4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -722,7 +722,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
INIT_LIST_HEAD(&driver->clients);
/* 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);
return 0;
@@ -782,7 +783,8 @@ void i2c_del_driver(struct i2c_driver *driver)
{
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);
pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 05710c7..47c0d85 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1453,7 +1453,8 @@ static void nodemgr_suspend_ne(struct node_entry *ne)
ne->in_limbo = 1;
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;
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]",
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)
{
- 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
* improvement...) */
- class_for_each_device(&nodemgr_ne_class, ¶m, __nodemgr_node_probe);
+ class_for_each_device(&nodemgr_ne_class, NULL, ¶m,
+ __nodemgr_node_probe);
/* 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
@@ -1826,7 +1830,7 @@ int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
hip.cb = cb;
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);
return error;
diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
index a489227..936bae5 100644
--- a/drivers/power/apm_power.c
+++ b/drivers/power/apm_power.c
@@ -78,7 +78,7 @@ static void find_main_battery(void)
main_battery = NULL;
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);
if (error) {
main_battery = bp.main;
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index af1633e..cb1ccb4 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -41,7 +41,7 @@ static void power_supply_changed_work(struct work_struct *work)
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_update_leds(psy);
@@ -79,7 +79,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
{
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);
dev_dbg(psy->dev, "%s %d\n", __func__, error);
diff --git a/include/linux/device.h b/include/linux/device.h
index de17871..6d5b351 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -210,7 +210,8 @@ extern struct kobject *sysfs_dev_block_kobj;
extern struct kobject *sysfs_dev_char_kobj;
extern int __must_check class_register(struct class *class);
extern void class_unregister(struct class *class);
-extern int class_for_each_device(struct class *class, void *data,
+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,
int (*match)(struct device *, void *));
--
1.5.6.3
next prev parent reply other threads:[~2008-07-22 5:32 UTC|newest]
Thread overview: 97+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-22 5:18 [GIT PATCH] driver core patches against 2.6.26 Greg KH
2008-07-22 5:18 ` [PATCH 01/79] sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 02/79] kobject: replace '/' with '!' in name Greg Kroah-Hartman
2008-07-22 7:12 ` Kari Hurtta
2008-07-22 18:12 ` Ingo Oeser
2008-07-22 20:50 ` Greg KH
2008-07-22 23:25 ` [PATCH] kobject: Replace ALL occurrences of '/' with '!' instead of only the first one Ingo Oeser
2008-07-22 5:18 ` [PATCH 03/79] debugfs: Add a reference to the debugfs API documentation Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 04/79] Firmware: fix typo in example code Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 05/79] device create: block: convert device_create to device_create_drvdata Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 06/79] device create: char: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 07/79] device create: coda: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 08/79] device create: dca: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 09/79] device create: dvb: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 10/79] device create: framebuffer: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 11/79] device create: hid: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 12/79] device create: hwmon: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 13/79] device create: i2c: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 14/79] device create: ide: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 15/79] device create: ieee1394: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 16/79] device create: infiniband: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 17/79] device create: isdn: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 18/79] device create: macintosh: " Greg Kroah-Hartman
2008-07-22 22:00 ` Benjamin Herrenschmidt
2008-07-22 5:18 ` [PATCH 19/79] device create: mips: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 20/79] device create: misc: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 21/79] device create: mtd: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 22/79] device create: net: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 23/79] device create: s390: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 24/79] device create: scsi: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 25/79] device create: sound: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 26/79] device create: spi: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 27/79] device create: usb: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 28/79] device create: x86: " Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 29/79] driver core: remove device_create() Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 30/79] device create: convert device_create_drvdata to device_create Greg Kroah-Hartman
2008-07-22 5:18 ` Greg Kroah-Hartman [this message]
2008-07-22 5:18 ` [PATCH 32/79] Driver Core: add ability for class_find_device to start in middle of list Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 33/79] block: fix compiler warning in genhd.c Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 34/79] block: make printk_partition use the class iterator function Greg Kroah-Hartman
2008-07-22 5:18 ` [PATCH 35/79] block: make blk_lookup_devt " Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 36/79] block: make /proc/diskstats only build if CONFIG_PROC_FS is enabled Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 37/79] block: make proc files seq_start use the class_find_device() Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 38/79] block: move header for /proc/partitions to seq_start Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 39/79] block: make /proc/partitions and /proc/diskstats use class_find_device() Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 40/79] infiniband: rename "device" to "ib_device" in cm_device Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 41/79] infiniband: make cm_device use a struct device and not a kobject Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 42/79] bluetooth: remove improper bluetooth class symlinks Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 43/79] class: move driver core specific parts to a private structure Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 44/79] class: rename "devices" to "class_devices" in internal class structure Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 45/79] class: rename "interfaces" to "class_interfaces" " Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 46/79] class: rename "subsys" to "class_subsys" " Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 47/79] class: rename "sem" to "class_sem" " Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 48/79] class: fix docbook comments for class_private structure Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 49/79] class: add lockdep infrastructure Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 50/79] class: change internal semaphore to a mutex Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 51/79] driver core: remove KOBJ_NAME_LEN define Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 52/79] driver core: remove DEVICE_NAME_SIZE define Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 53/79] driver core: remove DEVICE_ID_SIZE define Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 54/79] driver core: fix a lot of printk usages of bus_id Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 55/79] pnp: add acpi:* modalias entries Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 56/79] UIO: fix UIO Kconfig dependencies Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 57/79] UIO: Add write function to allow irq masking Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 58/79] UIO: add generic UIO platform driver Greg Kroah-Hartman
2008-07-22 11:34 ` Uwe Kleine-König
2008-07-22 17:13 ` Greg KH
2008-07-22 5:19 ` [PATCH 59/79] UIO: minor style and comment fixes Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 60/79] kobject: reorder kobject to save space on 64 bit builds Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 61/79] kobject: should use kobject_put() in kset-example Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 62/79] sysdev: fix debugging statements in registration code Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 63/79] sysfs: don't call notify_change Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 64/79] uio-howto.tmpl: use standard copyright/legal markings Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 65/79] uio-howto.tmpl: use unique output names Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 66/79] always enable FW_LOADER unless EMBEDDED=y Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 67/79] HOWTO: change email addresses of James in HOWTO Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 68/79] debugfs: Implement debugfs_remove_recursive() Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 69/79] sysfs-rules.txt: reword API stability statement Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 70/79] kobject: Transmit return value of call_usermodehelper() to caller Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 71/79] driver core: Suppress sysfs warnings for device_rename() Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 72/79] sysdev: Pass the attribute to the low level sysdev show/store function Greg Kroah-Hartman
2008-07-22 20:40 ` Andrew Morton
2008-07-22 20:49 ` Greg KH
2008-07-22 21:03 ` Andrew Morton
2008-07-22 21:19 ` Greg KH
2008-07-23 3:04 ` Stephen Rothwell
2008-07-23 4:22 ` Greg KH
2008-07-23 9:03 ` Ingo Molnar
2008-07-23 14:03 ` Greg KH
2008-07-22 5:19 ` [PATCH 73/79] sysdev: Add utility functions for simple int/ulong variable sysdev attributes Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 74/79] sysdev: Convert the x86 mce tolerant sysdev attribute to generic attribute Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 75/79] HP iLO driver Greg Kroah-Hartman
2008-07-22 17:11 ` Altobelli, David
2008-07-22 17:16 ` Greg KH
2008-07-22 5:19 ` [PATCH 76/79] MTD: handle pci_name() being const Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 77/79] 3c59x: " Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 78/79] sparc64: fix up bus_id changes in sparc core code Greg Kroah-Hartman
2008-07-22 5:19 ` [PATCH 79/79] arm: bus_id -> dev_name() and dev_set_name() conversions Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1216703983-21448-31-git-send-email-gregkh@suse.de \
--to=gregkh@suse.de \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome