public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Cc: Kay Sievers <kay.sievers@novell.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 2/36] Driver core: fix "driver" symlink timing
Date: Fri,  1 Dec 2006 15:21:32 -0800	[thread overview]
Message-ID: <11650153293531-git-send-email-greg@kroah.com> (raw)
In-Reply-To: <11650153262399-git-send-email-greg@kroah.com>

From: Kay Sievers <kay.sievers@novell.com>

Create the "driver" link before the child device may be created by
the probing logic. This makes it possible for userspace (udev), to
determine the driver property of the parent device, at the time the
child device is created.

Signed-off-by: Kay Sievers <kay.sievers@novell.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/dd.c |   82 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 9c88b1e..510e788 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -26,28 +26,12 @@
 #define to_drv(node) container_of(node, struct device_driver, kobj.entry)
 
 
-/**
- *	device_bind_driver - bind a driver to one device.
- *	@dev:	device.
- *
- *	Allow manual attachment of a driver to a device.
- *	Caller must have already set @dev->driver.
- *
- *	Note that this does not modify the bus reference count
- *	nor take the bus's rwsem. Please verify those are accounted
- *	for before calling this. (It is ok to call with no other effort
- *	from a driver's probe() method.)
- *
- *	This function must be called with @dev->sem held.
- */
-int device_bind_driver(struct device *dev)
+static void driver_bound(struct device *dev)
 {
-	int ret;
-
 	if (klist_node_attached(&dev->knode_driver)) {
 		printk(KERN_WARNING "%s: device %s already bound\n",
 			__FUNCTION__, kobject_name(&dev->kobj));
-		return 0;
+		return;
 	}
 
 	pr_debug("bound device '%s' to driver '%s'\n",
@@ -58,6 +42,12 @@ int device_bind_driver(struct device *de
 					     BUS_NOTIFY_BOUND_DRIVER, dev);
 
 	klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
+}
+
+static int driver_sysfs_add(struct device *dev)
+{
+	int ret;
+
 	ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj,
 			  kobject_name(&dev->kobj));
 	if (ret == 0) {
@@ -70,6 +60,36 @@ int device_bind_driver(struct device *de
 	return ret;
 }
 
+static void driver_sysfs_remove(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+
+	if (drv) {
+		sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
+		sysfs_remove_link(&dev->kobj, "driver");
+	}
+}
+
+/**
+ *	device_bind_driver - bind a driver to one device.
+ *	@dev:	device.
+ *
+ *	Allow manual attachment of a driver to a device.
+ *	Caller must have already set @dev->driver.
+ *
+ *	Note that this does not modify the bus reference count
+ *	nor take the bus's rwsem. Please verify those are accounted
+ *	for before calling this. (It is ok to call with no other effort
+ *	from a driver's probe() method.)
+ *
+ *	This function must be called with @dev->sem held.
+ */
+int device_bind_driver(struct device *dev)
+{
+	driver_bound(dev);
+	return driver_sysfs_add(dev);
+}
+
 struct stupid_thread_structure {
 	struct device_driver *drv;
 	struct device *dev;
@@ -90,30 +110,32 @@ static int really_probe(void *void_data)
 		 drv->bus->name, drv->name, dev->bus_id);
 
 	dev->driver = drv;
+	if (driver_sysfs_add(dev)) {
+		printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n",
+			__FUNCTION__, dev->bus_id);
+		goto probe_failed;
+	}
+
 	if (dev->bus->probe) {
 		ret = dev->bus->probe(dev);
-		if (ret) {
-			dev->driver = NULL;
+		if (ret)
 			goto probe_failed;
-		}
 	} else if (drv->probe) {
 		ret = drv->probe(dev);
-		if (ret) {
-			dev->driver = NULL;
+		if (ret)
 			goto probe_failed;
-		}
-	}
-	if (device_bind_driver(dev)) {
-		printk(KERN_ERR "%s: device_bind_driver(%s) failed\n",
-			__FUNCTION__, dev->bus_id);
-		/* How does undo a ->probe?  We're screwed. */
 	}
+
+	driver_bound(dev);
 	ret = 1;
 	pr_debug("%s: Bound Device %s to Driver %s\n",
 		 drv->bus->name, dev->bus_id, drv->name);
 	goto done;
 
 probe_failed:
+	driver_sysfs_remove(dev);
+	dev->driver = NULL;
+
 	if (ret == -ENODEV || ret == -ENXIO) {
 		/* Driver matched, but didn't support device
 		 * or device not found.
@@ -289,7 +311,7 @@ static void __device_release_driver(stru
 	drv = dev->driver;
 	if (drv) {
 		get_driver(drv);
-		sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
+		driver_sysfs_remove(dev);
 		sysfs_remove_link(&dev->kobj, "driver");
 		klist_remove(&dev->knode_driver);
 
-- 
1.4.4.1


  reply	other threads:[~2006-12-01 23:22 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-01 23:16 [GIT PATCH] Driver core patches for 2.6.19 Greg KH
2006-12-01 23:21 ` [PATCH 1/36] Driver core: add notification of bus events Greg KH
2006-12-01 23:21   ` Greg KH [this message]
2006-12-01 23:21     ` [PATCH 3/36] Driver Core: Move virtual_device_parent() to core.c Greg KH
2006-12-01 23:21       ` [PATCH 4/36] CONFIG_SYSFS_DEPRECATED Greg KH
2006-12-01 23:21         ` [PATCH 5/36] Driver core: make old versions of udev work properly Greg KH
2006-12-01 23:21           ` [PATCH 6/36] CONFIG_SYSFS_DEPRECATED - bus symlinks Greg KH
2006-12-01 23:21             ` [PATCH 7/36] CONFIG_SYSFS_DEPRECATED - device symlinks Greg KH
2006-12-01 23:21               ` [PATCH 8/36] CONFIG_SYSFS_DEPRECATED - PHYSDEV* uevent variables Greg KH
2006-12-01 23:21                 ` [PATCH 9/36] CONFIG_SYSFS_DEPRECATED - class symlinks Greg KH
2006-12-01 23:21                   ` [PATCH 10/36] Driver core: convert vt code to use struct device Greg KH
2006-12-01 23:21                     ` [PATCH 11/36] Driver core: convert vc " Greg KH
2006-12-01 23:21                       ` [PATCH 12/36] Driver core: change misc class_devices to be real devices Greg KH
2006-12-01 23:21                         ` [PATCH 13/36] Driver core: convert tty core to use struct device Greg KH
2006-12-01 23:21                           ` [PATCH 14/36] Driver core: convert raw device code " Greg KH
2006-12-01 23:21                             ` [PATCH 15/36] I2C: convert i2c-dev to use struct device instead of struct class_device Greg KH
2006-12-01 23:21                               ` [PATCH 16/36] Driver core: convert msr code to use struct device Greg KH
2006-12-01 23:21                                 ` [PATCH 17/36] Driver core: convert cpuid " Greg KH
2006-12-01 23:21                                   ` [PATCH 18/36] Driver core: convert PPP " Greg KH
2006-12-01 23:21                                     ` [PATCH 19/36] Driver core: convert ppdev " Greg KH
2006-12-01 23:21                                       ` [PATCH 20/36] Driver core: convert mmc " Greg KH
2006-12-01 23:21                                         ` [PATCH 21/36] Driver core: convert firmware " Greg KH
2006-12-01 23:21                                           ` [PATCH 22/36] Driver core: convert fb " Greg KH
2006-12-01 23:21                                             ` [PATCH 23/36] Driver core: change mem class_devices to be real devices Greg KH
2006-12-01 23:21                                               ` [PATCH 24/36] Driver core: convert sound core to use struct device Greg KH
2006-12-01 23:21                                                 ` [PATCH 25/36] Driver core: add dev_archdata to " Greg KH
2006-12-01 23:21                                                   ` [PATCH 26/36] ACPI: Change ACPI to use dev_archdata instead of firmware_data Greg KH
2006-12-01 23:21                                                     ` [PATCH 27/36] Driver core: Call platform_notify_remove later Greg KH
2006-12-01 23:21                                                       ` [PATCH 28/36] cpu topology: consider sysfs_create_group return value Greg KH
2006-12-01 23:21                                                         ` [PATCH 29/36] sysfs: sysfs_write_file() writes zero terminated data Greg KH
2006-12-01 23:22                                                           ` [PATCH 30/36] driver core: Introduce device_find_child() Greg KH
2006-12-01 23:22                                                             ` [PATCH 31/36] Driver core: make drivers/base/core.c:setup_parent() static Greg KH
2006-12-01 23:22                                                               ` [PATCH 32/36] driver core: Introduce device_move(): move a device to a new parent Greg KH
2006-12-01 23:22                                                                 ` [PATCH 33/36] driver core: Use klist_remove() in device_move() Greg KH
2006-12-01 23:22                                                                   ` [PATCH 34/36] Driver core: platform_driver_probe(), can save codespace Greg KH
2006-12-01 23:22                                                                     ` [PATCH 35/36] Documentation/driver-model/platform.txt update/rewrite Greg KH
2006-12-01 23:22                                                                       ` [PATCH 36/36] Driver core: show drivers in /sys/module/ Greg KH
2006-12-03 16:26                                                                 ` [PATCH 32/36] driver core: Introduce device_move(): move a device to a new parent Marcel Holtmann
2006-12-04 19:58                                                                   ` Greg KH
2006-12-04 21:15                                                                     ` Marcel Holtmann
2006-12-04 23:05                                                                       ` Greg KH
2006-12-05 15:26                                                                         ` Marcel Holtmann
2006-12-06  5:58                                                                           ` Greg KH
2006-12-06  8:29                                                                             ` Marcel Holtmann
2006-12-06  9:03                                                                           ` Martin Schwidefsky
2007-01-08 13:21                                                                           ` Cornelia Huck

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=11650153293531-git-send-email-greg@kroah.com \
    --to=greg@kroah.com \
    --cc=gregkh@suse.de \
    --cc=kay.sievers@novell.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