[PATCH] driver core: Add the ability to unbind drivers to devices from userspace

Greg KH
2005-06-24T05:16:43Z

This adds a single file, "unbind", to the sysfs directory of every
device that is currently bound to a driver. To unbind the driver from
the device, write anything to this file and they will be disconnected
from each other.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
drivers/base/dd.c | 11 +++++++++++
1 files changed, 11 insertions(+)

--- gregkh-2.6.orig/drivers/base/dd.c 2005-06-22 17:56:48.000000000 -0700
+++ gregkh-2.6/drivers/base/dd.c 2005-06-22 17:56:59.000000000 -0700
@@ -23,6 +23,15 @@

#define to_drv(node) container_of(node, struct device_driver, kobj.entry)

+/* manually detach a device from it's associated driver. */
+/* Any write will cause it to happen. */
+static ssize_t device_unbind(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ device_release_driver(dev);
+ return count;
+}
+static DEVICE_ATTR(unbind, S_IWUSR, NULL, device_unbind);

/**
* device_bind_driver - bind a driver to one device.
@@ -46,6 +55,7 @@
sysfs_create_link(&dev->driver->kobj, &dev->kobj,
kobject_name(&dev->kobj));
sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver");
+ device_create_file(dev, &dev_attr_unbind);
}

/**
@@ -191,6 +201,7 @@
get_driver(drv);
sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
sysfs_remove_link(&dev->kobj, "driver");
+ device_remove_file(dev, &dev_attr_unbind);
klist_remove(&dev->knode_driver);

if (drv->remove)