From: Sebastian Ott <sebott@linux.vnet.ibm.com>
To: Greg KH <gregkh@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] driver-core: fix race between device_register and driver_register
Date: Tue, 12 Apr 2011 19:05:37 +0200 (CEST) [thread overview]
Message-ID: <alpine.LFD.2.02.1104121903170.2025@c4eb> (raw)
In-Reply-To: <20110412160220.GA28483@suse.de>
When a device is registered to a bus it will be a) added to the list
of devices of the bus and b) bind to a driver (if one matches). As a
result of a driver being registered at this bus between a) and b) this
device could already be bound to a driver. This leads to a warning
and incorrect refcounting.
To fix this add a check to device_attach to identify an already bound
device.
Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
---
drivers/base/dd.c | 5 +++++
1 file changed, 5 insertions(+)
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -245,6 +245,10 @@ int device_attach(struct device *dev)
device_lock(dev);
if (dev->driver) {
+ if (klist_node_attached(&dev->p->knode_driver)) {
+ ret = 1;
+ goto out_unlock;
+ }
ret = device_bind_driver(dev);
if (ret == 0)
ret = 1;
@@ -257,6 +261,7 @@ int device_attach(struct device *dev)
ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
pm_runtime_put_sync(dev);
}
+out_unlock:
device_unlock(dev);
return ret;
}
next prev parent reply other threads:[~2011-04-12 17:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-11 14:04 sysfs: cannot create duplicate filename Sebastian Ott
2011-04-11 14:13 ` Greg KH
2011-04-11 14:33 ` Sebastian Ott
2011-04-11 14:49 ` Greg KH
2011-04-11 15:05 ` Sebastian Ott
2011-04-11 15:19 ` Greg KH
2011-04-11 17:50 ` Sebastian Ott
2011-04-11 17:56 ` Greg KH
2011-04-12 14:39 ` Sebastian Ott
2011-04-12 16:02 ` Greg KH
2011-04-12 17:05 ` Sebastian Ott [this message]
2011-04-12 17:13 ` [PATCH] driver-core: fix race between device_register and driver_register 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=alpine.LFD.2.02.1104121903170.2025@c4eb \
--to=sebott@linux.vnet.ibm.com \
--cc=gregkh@suse.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.