aboutsummaryrefslogtreecommitdiffstats
path: root/driver
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2006-06-28 17:43:59 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-28 17:43:59 -0700
commit9716ed1bd85214afb9a25b2d306254530b1802a5 (patch)
treecbb3204fa2c50c7ce14a4c74d4ba48221a7d6599 /driver
parent53d9687f8faa903da0fd5d5a665ca99a76e68dfa (diff)
downloadpatches-9716ed1bd85214afb9a25b2d306254530b1802a5.tar.gz
add ability to move network devices to use struct device
Diffstat (limited to 'driver')
-rw-r--r--driver/device-class-attr.patch149
-rw-r--r--driver/device-class-parent.patch73
-rw-r--r--driver/put_device-might_sleep.patch2
3 files changed, 223 insertions, 1 deletions
diff --git a/driver/device-class-attr.patch b/driver/device-class-attr.patch
new file mode 100644
index 0000000000000..4b230571bd6b6
--- /dev/null
+++ b/driver/device-class-attr.patch
@@ -0,0 +1,149 @@
+From foo@baz Tue Apr 9 12:12:43 2002
+Date: Wed, 28 Jun 2006 16:19:58 -0700
+To: Greg KH <greg@kroah.com>
+From: Greg Kroah-Hartman <gregkh@suse.de>
+Subject: Driver core: add ability for classes to handle devices properly
+
+This adds two new callbacks to the class structure:
+ int (*dev_uevent)(struct device *dev, char **envp, int num_envp,
+ char *buffer, int buffer_size);
+ void (*dev_release)(struct device *dev);
+
+And one pointer:
+ struct device_attribute * dev_attrs;
+
+which all corrispond with the same thing as the "normal" class devices
+do, yet this is for when a struct device is bound to a class.
+
+Someday soon, struct class_device will go away, and then the other
+fields in this structure can be removed too. But this is necessary in
+order to get the transition to work properly.
+
+Tested out on a network core patch that converted it to use struct
+device instead of struct class_device.
+
+
+Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
+
+
+---
+ drivers/base/core.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
+ include/linux/device.h | 4 +++
+ 2 files changed, 57 insertions(+)
+
+--- gregkh-2.6.orig/drivers/base/core.c
++++ gregkh-2.6/drivers/base/core.c
+@@ -95,6 +95,8 @@ static void device_release(struct kobjec
+
+ if (dev->release)
+ dev->release(dev);
++ else if (dev->class && dev->class->dev_release)
++ dev->class->dev_release(dev);
+ else {
+ printk(KERN_ERR "Device '%s' does not have a release() function, "
+ "it is broken and must be fixed.\n",
+@@ -180,6 +182,15 @@ static int dev_uevent(struct kset *kset,
+ }
+ }
+
++ if (dev->class && dev->class->dev_uevent) {
++ /* have the class specific function add its stuff */
++ retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size);
++ if (retval) {
++ pr_debug("%s - dev_uevent() returned %d\n",
++ __FUNCTION__, retval);
++ }
++ }
++
+ return retval;
+ }
+
+@@ -225,6 +236,43 @@ static void device_remove_groups(struct
+ }
+ }
+
++static int device_add_attrs(struct device *dev)
++{
++ struct class *class = dev->class;
++ int error = 0;
++ int i;
++
++ if (!class)
++ return 0;
++
++ if (class->dev_attrs) {
++ for (i = 0; attr_name(class->dev_attrs[i]); i++) {
++ error = device_create_file(dev, &class->dev_attrs[i]);
++ if (error)
++ break;
++ }
++ }
++ if (error)
++ while (--i >= 0)
++ device_remove_file(dev, &class->dev_attrs[i]);
++ return error;
++}
++
++static void device_remove_attrs(struct device *dev)
++{
++ struct class *class = dev->class;
++ int i;
++
++ if (!class)
++ return;
++
++ if (class->dev_attrs) {
++ for (i = 0; attr_name(class->dev_attrs[i]); i++)
++ device_remove_file(dev, &class->dev_attrs[i]);
++ }
++}
++
++
+ static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
+ char *buf)
+ {
+@@ -379,6 +427,8 @@ int device_add(struct device *dev)
+ }
+ }
+
++ if ((error = device_add_attrs(dev)))
++ goto AttrsError;
+ if ((error = device_add_groups(dev)))
+ goto GroupError;
+ if ((error = device_pm_add(dev)))
+@@ -409,6 +459,8 @@ int device_add(struct device *dev)
+ PMError:
+ device_remove_groups(dev);
+ GroupError:
++ device_remove_attrs(dev);
++ AttrsError:
+ if (dev->devt_attr) {
+ device_remove_file(dev, dev->devt_attr);
+ kfree(dev->devt_attr);
+@@ -506,6 +558,7 @@ void device_del(struct device * dev)
+ }
+ device_remove_file(dev, &dev->uevent_attr);
+ device_remove_groups(dev);
++ device_remove_attrs(dev);
+
+ /* Notify the platform of the removal, in case they
+ * need to do anything...
+--- gregkh-2.6.orig/include/linux/device.h
++++ gregkh-2.6/include/linux/device.h
+@@ -148,12 +148,16 @@ struct class {
+
+ struct class_attribute * class_attrs;
+ struct class_device_attribute * class_dev_attrs;
++ struct device_attribute * dev_attrs;
+
+ int (*uevent)(struct class_device *dev, char **envp,
+ int num_envp, char *buffer, int buffer_size);
++ int (*dev_uevent)(struct device *dev, char **envp, int num_envp,
++ char *buffer, int buffer_size);
+
+ void (*release)(struct class_device *dev);
+ void (*class_release)(struct class *class);
++ void (*dev_release)(struct device *dev);
+ };
+
+ extern int class_register(struct class *);
diff --git a/driver/device-class-parent.patch b/driver/device-class-parent.patch
new file mode 100644
index 0000000000000..4db7d4c41fb8d
--- /dev/null
+++ b/driver/device-class-parent.patch
@@ -0,0 +1,73 @@
+From foo@baz Tue Apr 9 12:12:43 2002
+Date: Wed, 28 Jun 2006 16:19:58 -0700
+To: Greg KH <greg@kroah.com>
+From: Greg Kroah-Hartman <gregkh@suse.de>
+Subject: Driver core: allow devices in classes to have no parent
+
+This fixes an oops when a device is attached to a class, yet has no
+"parent" device. An example of this would be the "lo" device in the
+network core.
+
+We should create a "virtual" subdirectory under /sys/devices/ for these,
+but no one seems to agree on a proper name for it yet...
+
+Oh, and update my copyright on the driver core.
+
+Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
+
+
+---
+ drivers/base/core.c | 21 +++++++++++----------
+ 1 file changed, 11 insertions(+), 10 deletions(-)
+
+--- gregkh-2.6.orig/drivers/base/core.c
++++ gregkh-2.6/drivers/base/core.c
+@@ -3,6 +3,8 @@
+ *
+ * Copyright (c) 2002-3 Patrick Mochel
+ * Copyright (c) 2002-3 Open Source Development Labs
++ * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
++ * Copyright (c) 2006 Novell, Inc.
+ *
+ * This file is released under the GPLv2
+ *
+@@ -370,10 +372,11 @@ int device_add(struct device *dev)
+ "subsystem");
+ sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
+ dev->bus_id);
+-
+- sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
+- class_name = make_class_name(dev->class->name, &dev->kobj);
+- sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
++ if (parent) {
++ sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
++ class_name = make_class_name(dev->class->name, &dev->kobj);
++ sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
++ }
+ }
+
+ if ((error = device_add_groups(dev)))
+@@ -492,8 +495,10 @@ void device_del(struct device * dev)
+ sysfs_remove_link(&dev->kobj, "subsystem");
+ sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
+ class_name = make_class_name(dev->class->name, &dev->kobj);
+- sysfs_remove_link(&dev->kobj, "device");
+- sysfs_remove_link(&dev->parent->kobj, class_name);
++ if (parent) {
++ sysfs_remove_link(&dev->kobj, "device");
++ sysfs_remove_link(&dev->parent->kobj, class_name);
++ }
+ kfree(class_name);
+ down(&dev->class->sem);
+ list_del_init(&dev->node);
+@@ -622,10 +627,6 @@ struct device *device_create(struct clas
+
+ if (class == NULL || IS_ERR(class))
+ goto error;
+- if (parent == NULL) {
+- printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__);
+- goto error;
+- }
+
+ dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+ if (!dev) {
diff --git a/driver/put_device-might_sleep.patch b/driver/put_device-might_sleep.patch
index adb9bb8f6f54a..ea053150c3312 100644
--- a/driver/put_device-might_sleep.patch
+++ b/driver/put_device-might_sleep.patch
@@ -12,7 +12,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
--- gregkh-2.6.orig/drivers/base/core.c
+++ gregkh-2.6/drivers/base/core.c
-@@ -460,6 +460,7 @@ struct device * get_device(struct device
+@@ -515,6 +515,7 @@ struct device * get_device(struct device
*/
void put_device(struct device * dev)
{