public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: Add the ability to unbind drivers to devices from userspace
@ 2005-07-25  4:09 Jon Smirl
  2005-07-25  4:58 ` Dmitry Torokhov
  0 siblings, 1 reply; 57+ messages in thread
From: Jon Smirl @ 2005-07-25  4:09 UTC (permalink / raw)
  To: Greg KH; +Cc: lkml

I just pulled from GIT to test bind/unbind. I couldn't get it to work;
it isn't taking into account the CR on the end of the input value of
the sysfs attribute.  This patch will fix it but I'm sure there is a
cleaner solution.

-- 
Jon Smirl
jonsmirl@gmail.com


diff --git a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -137,9 +137,11 @@ decl_subsys(bus, &ktype_bus, NULL);
 static int driver_helper(struct device *dev, void *data)
 {
        const char *name = data;
-
-       if (strcmp(name, dev->bus_id) == 0)
+printk(KERN_ERR "unbind: %s %s\n", name, dev->bus_id);
+       if (strncmp(name, dev->bus_id, strlen(dev->bus_id)) == 0) {
+printk(KERN_ERR "match\n");
                return 1;
+       }
        return 0;
 }

^ permalink raw reply	[flat|nested] 57+ messages in thread
* [PATCH] driver core: add bus_find_device & driver_find_device functions
@ 2005-06-30  6:04 Greg KH
  2005-06-30  6:04 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
  0 siblings, 1 reply; 57+ messages in thread
From: Greg KH @ 2005-06-30  6:04 UTC (permalink / raw)
  To: linux-kernel; +Cc: cohuck

[PATCH] driver core: add bus_find_device & driver_find_device functions

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.

Signed-off-by: Cornelia Huck <cohuck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
commit 0edb586049e57c56e625536476931117a57671e9
tree 9d92bb9821d134d199d62de1ff3096ff2b73fdc7
parent fd782a4a99d2d3e818b9465c427b10f7f027d7da
author Cornelia Huck <cohuck@de.ibm.com> Wed, 22 Jun 2005 16:59:51 +0200
committer Greg Kroah-Hartman <gregkh@suse.de> Wed, 29 Jun 2005 22:48:03 -0700

 drivers/base/bus.c     |   34 ++++++++++++++++++++++++++++++++++
 drivers/base/driver.c  |   35 +++++++++++++++++++++++++++++++++++
 include/linux/device.h |    5 +++++
 3 files changed, 74 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,39 @@ 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 0 if the device doesn't match and non-zero
+ * if it does.  If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more devices.
+ */
+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)
@@ -557,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 0 if the device doesn't match and non-zero
+ * if it does.  If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more devices.
+ */
+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
@@ -80,6 +80,8 @@ 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 *));
@@ -142,6 +144,9 @@ 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 *));
 
 
 /*


^ permalink raw reply	[flat|nested] 57+ messages in thread
* [RFC] bind and unbind drivers from userspace through sysfs
@ 2005-06-24  5:12 Greg KH
  2005-06-24  5:14 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
  0 siblings, 1 reply; 57+ messages in thread
From: Greg KH @ 2005-06-24  5:12 UTC (permalink / raw)
  To: linux-kernel; +Cc: Patrick Mochel

Now that we have the internal infrastructure of the driver model
reworked so the locks aren't so global and imposing, it's possible to
bind and unbind drivers from devices from userspace with only a very
tiny ammount of code.

In reply to this email, are two patches, one that adds bind and one that
adds unbind functionality.  I've added these to my trees and should show
up in the next -mm releases.  Comments appreciated.

Oh, and yes, we still need a way to add new device ids to drivers from
sysfs, like PCI currently has.  I'll be working on that next.

Even so, with these two patches, people should be able to do things that
they have been wanting to do for a while (like take over the what driver
to what device logic in userspace, as I know some distro installers
really want to do.)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 57+ messages in thread

end of thread, other threads:[~2005-08-21 22:21 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-25  4:09 [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Jon Smirl
2005-07-25  4:58 ` Dmitry Torokhov
2005-07-25 14:28   ` Jon Smirl
2005-07-25 14:48     ` Dmitry Torokhov
2005-07-25 16:30       ` Jon Smirl
2005-07-26  0:00         ` Greg KH
2005-07-26  0:28           ` Jon Smirl
2005-07-26  0:30             ` Greg KH
2005-07-26  0:56               ` Jon Smirl
2005-07-26  1:54                 ` Greg KH
2005-07-26  3:15                   ` Jon Smirl
2005-07-26  3:29                     ` Dmitry Torokhov
2005-07-28  2:05                     ` Jon Smirl
2005-07-28  3:46                       ` Greg KH
2005-07-28  3:59                         ` Jon Smirl
2005-07-28  4:05                           ` Greg KH
2005-07-28  4:49                             ` Jon Smirl
2005-07-28  5:49                               ` Greg KH
2005-07-28  7:04                                 ` Mitchell Blank Jr
2005-07-28 12:54                                   ` Jon Smirl
2005-07-28 13:09                                     ` Oliver Neukum
2005-07-28 13:16                                     ` Paulo Marques
2005-07-28 18:09                                     ` Mitchell Blank Jr
2005-07-28 19:03                                     ` Greg KH
2005-07-28 19:57                                       ` Jon Smirl
2005-07-28 20:22                                         ` Mitchell Blank Jr
2005-07-28 20:27                                           ` Jon Smirl
2005-07-29 18:50                                             ` Jon Smirl
2005-08-06  0:42                                               ` Greg KH
2005-08-06  3:48                                                 ` Jon Smirl
2005-08-21 22:21                                             ` Jon Smirl
2005-07-28 21:10                                         ` Oliver Neukum
2005-07-28 21:12                                           ` Jon Smirl
2002-01-01  7:53                                             ` Pavel Machek
2005-08-05 13:32                                               ` Jon Smirl
2005-08-05 18:01                                                 ` Oliver Neukum
2005-08-05 18:14                                                   ` Jon Smirl
2005-08-05 18:20                                                     ` Oliver Neukum
2005-08-05 18:47                                                       ` Jon Smirl
2005-08-05 20:07                                                         ` Oliver Neukum
2005-08-05 20:33                                                           ` Jon Smirl
2005-08-06  9:39                                                             ` Oliver Neukum
2005-08-07 18:50                                                             ` Pavel Machek
2005-08-07 18:47                                                 ` Pavel Machek
2005-08-07 20:17                                                   ` Jon Smirl
2005-08-07 21:06                                                     ` Pavel Machek
2005-08-05 22:31                                               ` David Weinehall
2005-07-28 21:17                                             ` Oliver Neukum
2005-07-28 12:52                                 ` Jon Smirl
  -- strict thread matches above, loose matches on Subject: below --
2005-06-30  6:04 [PATCH] driver core: add bus_find_device & driver_find_device functions Greg KH
2005-06-30  6:04 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
2005-06-30  6:25   ` Dmitry Torokhov
2005-06-30  6:29     ` Greg KH
2005-06-24  5:12 [RFC] bind and unbind drivers from userspace through sysfs Greg KH
2005-06-24  5:14 ` [PATCH] driver core: Add the ability to unbind drivers to devices from userspace Greg KH
2005-06-24 15:57   ` Patrick Mochel
2005-06-25  3:27     ` Greg KH
2005-06-25  4:16       ` Dmitry Torokhov
2005-06-25  9:39         ` Michael Tokarev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox