From: Cornelia Huck <cohuck@de.ibm.com>
To: Greg KH <gregkh@suse.de>
Cc: Greg KH <greg@kroah.com>,
akpm@osdl.org, linux-kernel@vger.kernel.org,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
mochel@digitalimplant.org
Subject: [patch 1/2] s390: klist bus_find_device & driver_find_device callback.
Date: Wed, 22 Jun 2005 16:59:51 +0200 [thread overview]
Message-ID: <20050622165951.7d736a16@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20050622081411.GA30791@suse.de>
[patch 1/2] s390: klist bus_find_device & driver_find_device callback.
Add bus_find_device() and driver_find_device() which allow searching for a
device in the bus's resp. the driver's klist and obtain a reference on it.
This version now increases the reference count for the device to be returned.
Also, the interface has been exported to GPL modules and the comments have
been improved.
Signed-off-by: Cornelia Huck <cohuck@de.ibm.com>
drivers/base/bus.c | 33 +++++++++++++++++++++++++++++++++
drivers/base/driver.c | 35 +++++++++++++++++++++++++++++++++++
include/linux/device.h | 7 +++++++
3 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -177,6 +177,38 @@ int bus_for_each_dev(struct bus_type * b
return error;
}
+/**
+ * bus_find_device - device iterator for locating a particular device.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @data: Data to pass to match function
+ * @match: Callback function to check device
+ *
+ * This is similar to the bus_for_each_dev() function above, but it
+ * returns a reference to a device that is 'found' for later use, as determined
+ * by the @match callback. The callback should return a bool - 0 if
+ * the device doesn't match and 1 if it does.
+ * The function will return if a device is found.
+ */
+
+struct device * bus_find_device(struct bus_type * bus,
+ struct device * start, void * data,
+ int (*match)(struct device *, void *))
+{
+ struct klist_iter i;
+ struct device * dev;
+
+ if (!bus)
+ return NULL;
+
+ klist_iter_init_node(&bus->klist_devices, &i,
+ (start ? &start->knode_bus : NULL));
+ while ((dev = next_device(&i)))
+ if (match(dev, data) && get_device(dev))
+ break;
+ klist_iter_exit(&i);
+ return dev;
+}
static struct device_driver * next_driver(struct klist_iter * i)
@@ -558,6 +590,7 @@ int __init buses_init(void)
EXPORT_SYMBOL_GPL(bus_for_each_dev);
+EXPORT_SYMBOL_GPL(bus_find_device);
EXPORT_SYMBOL_GPL(bus_for_each_drv);
EXPORT_SYMBOL_GPL(bus_add_device);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -56,6 +56,41 @@ EXPORT_SYMBOL_GPL(driver_for_each_device
/**
+ * driver_find_device - device iterator for locating a particular device.
+ * @driver: The device's driver
+ * @start: Device to begin with
+ * @data: Data to pass to match function
+ * @match: Callback function to check device
+ *
+ * This is similar to the driver_for_each_device() function above, but it
+ * returns a reference to a device that is 'found' for later use, as determined
+ * by the @match callback. The callback should return a bool - 0 if
+ * the device doesn't match and 1 if it does.
+ * The function will return if a device is found.
+ */
+
+struct device * driver_find_device(struct device_driver *drv,
+ struct device * start, void * data,
+ int (*match)(struct device *, void *))
+{
+ struct klist_iter i;
+ struct device * dev;
+
+ if (!drv)
+ return NULL;
+
+ klist_iter_init_node(&drv->klist_devices, &i,
+ (start ? &start->knode_driver : NULL));
+ while ((dev = next_device(&i)))
+ if (match(dev, data) && get_device(dev))
+ break;
+ klist_iter_exit(&i);
+ return dev;
+}
+
+EXPORT_SYMBOL_GPL(driver_find_device);
+
+/**
* driver_create_file - create sysfs file for driver.
* @drv: driver.
* @attr: driver attribute descriptor.
diff --git a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -81,6 +81,9 @@ extern struct bus_type * find_bus(char *
int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
int (*fn)(struct device *, void *));
+struct device * bus_find_device(struct bus_type * bus, struct device * start,
+ void * data, int (*match)(struct device *, void *));
+
int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
void * data, int (*fn)(struct device_driver *, void *));
@@ -143,6 +146,10 @@ extern void driver_remove_file(struct de
extern int driver_for_each_device(struct device_driver * drv, struct device * start,
void * data, int (*fn)(struct device *, void *));
+struct device * driver_find_device(struct device_driver * drv,
+ struct device * start, void * data,
+ int (*match)(struct device *, void *));
+
/*
* device classes
next prev parent reply other threads:[~2005-06-22 15:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-06-21 16:22 [patch 1/16] " Martin Schwidefsky
2005-06-22 6:26 ` Greg KH
2005-06-22 7:48 ` Cornelia Huck
2005-06-22 8:14 ` Greg KH
2005-06-22 14:59 ` Cornelia Huck
2005-06-22 14:59 ` Cornelia Huck [this message]
2005-06-22 14:59 ` [patch 2/2] s390: use klist in cio Cornelia Huck
2005-06-22 8:11 ` [patch 1/16] s390: klist bus_find_device & driver_find_device callback Christoph Hellwig
2005-06-22 8:19 ` Greg KH
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=20050622165951.7d736a16@gondolin.boeblingen.de.ibm.com \
--to=cohuck@de.ibm.com \
--cc=akpm@osdl.org \
--cc=greg@kroah.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@digitalimplant.org \
--cc=schwidefsky@de.ibm.com \
/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
all inboxes | Powered by JetHome®