From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] More Driver Core patches for 2.6.10-rc1
Date: Thu, 4 Nov 2004 16:48:25 -0800 [thread overview]
Message-ID: <1099615705183@kroah.com> (raw)
In-Reply-To: <1099615705170@kroah.com>
ChangeSet 1.2449.2.5, 2004/11/04 10:48:20-08:00, tj@home-tj.org
[PATCH] driver-model: bus_recan_devices() locking fix
df_02_bus_rescan_devcies_fix.patch
bus_rescan_devices() eventually calls device_attach() and thus
requires write locking the corresponding bus. The original code just
called bus_for_each_dev() which only read locks the bus. This patch
separates __bus_for_each_dev() and __bus_for_each_drv(), which don't
do locking themselves, out from the original functions and call them
with read lock in the original functions and with write lock in
bus_rescan_devices().
Signed-off-by: Tejun Heo <tj@home-tj.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/base/bus.c | 93 +++++++++++++++++++++++++++++++----------------------
1 files changed, 56 insertions(+), 37 deletions(-)
diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c 2004-11-04 16:30:46 -08:00
+++ b/drivers/base/bus.c 2004-11-04 16:30:46 -08:00
@@ -135,6 +135,52 @@
decl_subsys(bus, &ktype_bus, NULL);
+static int __bus_for_each_dev(struct bus_type *bus, struct device *start,
+ void *data, int (*fn)(struct device *, void *))
+{
+ struct list_head *head;
+ struct device *dev;
+ int error = 0;
+
+ if (!(bus = get_bus(bus)))
+ return -EINVAL;
+
+ head = &bus->devices.list;
+ dev = list_prepare_entry(start, head, bus_list);
+ list_for_each_entry_continue(dev, head, bus_list) {
+ get_device(dev);
+ error = fn(dev, data);
+ put_device(dev);
+ if (error)
+ break;
+ }
+ put_bus(bus);
+ return error;
+}
+
+static int __bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
+ void * data, int (*fn)(struct device_driver *, void *))
+{
+ struct list_head *head;
+ struct device_driver *drv;
+ int error = 0;
+
+ if (!(bus = get_bus(bus)))
+ return -EINVAL;
+
+ head = &bus->drivers.list;
+ drv = list_prepare_entry(start, head, kobj.entry);
+ list_for_each_entry_continue(drv, head, kobj.entry) {
+ get_driver(drv);
+ error = fn(drv, data);
+ put_driver(drv);
+ if (error)
+ break;
+ }
+ put_bus(bus);
+ return error;
+}
+
/**
* bus_for_each_dev - device iterator.
* @bus: bus type.
@@ -154,30 +200,16 @@
* to retain this data, it should do, and increment the reference
* count in the supplied callback.
*/
+
int bus_for_each_dev(struct bus_type * bus, struct device * start,
void * data, int (*fn)(struct device *, void *))
{
- struct device *dev;
- struct list_head * head;
- int error = 0;
-
- if (!(bus = get_bus(bus)))
- return -EINVAL;
-
- head = &bus->devices.list;
- dev = list_prepare_entry(start, head, bus_list);
+ int ret;
down_read(&bus->subsys.rwsem);
- list_for_each_entry_continue(dev, head, bus_list) {
- get_device(dev);
- error = fn(dev, data);
- put_device(dev);
- if (error)
- break;
- }
+ ret = __bus_for_each_dev(bus, start, data, fn);
up_read(&bus->subsys.rwsem);
- put_bus(bus);
- return error;
+ return ret;
}
/**
@@ -203,27 +235,12 @@
int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
void * data, int (*fn)(struct device_driver *, void *))
{
- struct list_head * head;
- struct device_driver *drv;
- int error = 0;
-
- if(!(bus = get_bus(bus)))
- return -EINVAL;
-
- head = &bus->drivers.list;
- drv = list_prepare_entry(start, head, kobj.entry);
+ int ret;
down_read(&bus->subsys.rwsem);
- list_for_each_entry_continue(drv, head, kobj.entry) {
- get_driver(drv);
- error = fn(drv, data);
- put_driver(drv);
- if(error)
- break;
- }
+ ret = __bus_for_each_drv(bus, start, data, fn);
up_read(&bus->subsys.rwsem);
- put_bus(bus);
- return error;
+ return ret;
}
/**
@@ -590,7 +607,9 @@
{
int count = 0;
- bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
+ down_write(&bus->subsys.rwsem);
+ __bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
+ up_write(&bus->subsys.rwsem);
return count;
}
next prev parent reply other threads:[~2004-11-05 0:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-11-05 0:35 [BK PATCH] More USB " Greg KH
2004-11-05 0:48 ` [PATCH] More Driver Core " Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH [this message]
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-05 0:48 ` Greg KH
2004-11-12 22:58 [BK PATCH] " Greg KH
2004-11-12 23:00 ` [PATCH] " Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
2004-11-12 23:00 ` Greg KH
[not found] ` <20041113000052.GC346@electric-eye.fr.zoreil.com>
[not found] ` <200411130020.17494.lists@kenneth.aafloy.net>
2004-11-13 0:44 ` 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=1099615705183@kroah.com \
--to=greg@kroah.com \
--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