<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From dtor_core@ameritech.net Sat Jul  9 23:23:29 2005
From: Dmitry Torokhov &lt;dtor_core@ameritech.net&gt;
To: Greg KH &lt;greg@kroah.com&gt;
Subject: Driver core: link device and all class devices derived from it.
Date: Sun, 10 Jul 2005 01:21:24 -0500
Cc: Neil Brown &lt;neilb@cse.unsw.edu.au&gt;, Vojtech Pavlik &lt;vojtech@suse.cz&gt;, Alan Stern &lt;stern@rowland.harvard.edu&gt;
Message-Id: &lt;200507100121.24956.dtor_core@ameritech.net&gt;

Driver core: link device and all class devices derived from it.

To ease the task of locating class devices derived from a certain
device create symlinks from parent device to its class devices.
Change USB host class device name from usbX to usb_hostX to avoid
conflict when creating aforementioned links.

Tweaked by Greg to have the symlink be "class_name:class_device_name" in
order to prevent duplicate links.

Signed-off-by: Dmitry Torokhov &lt;dtor@mail.ru&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@suse.de&gt;

---
 drivers/base/class.c   |   33 +++++++++++++++++++++++++++++++--
 drivers/usb/core/hcd.c |    2 +-
 2 files changed, 32 insertions(+), 3 deletions(-)

--- gregkh-2.6.orig/drivers/base/class.c	2005-08-17 23:27:02.000000000 -0700
+++ gregkh-2.6/drivers/base/class.c	2005-08-17 23:27:25.000000000 -0700
@@ -452,10 +452,29 @@ void class_device_initialize(struct clas
 	INIT_LIST_HEAD(&amp;class_dev-&gt;node);
 }
 
+static char *make_class_name(struct class_device *class_dev)
+{
+	char *name;
+	int size;
+
+	size = strlen(class_dev-&gt;class-&gt;name) +
+		strlen(kobject_name(&amp;class_dev-&gt;kobj)) + 2;
+
+	name = kmalloc(size, GFP_KERNEL);
+	if (!name)
+		return ERR_PTR(-ENOMEM);
+
+	strcpy(name, class_dev-&gt;class-&gt;name);
+	strcat(name, ":");
+	strcat(name, kobject_name(&amp;class_dev-&gt;kobj));
+	return name;
+}
+
 int class_device_add(struct class_device *class_dev)
 {
 	struct class * parent = NULL;
 	struct class_interface * class_intf;
+	char *class_name = NULL;
 	int error;
 
 	class_dev = class_device_get(class_dev);
@@ -500,9 +519,13 @@ int class_device_add(struct class_device
 	}
 
 	class_device_add_attrs(class_dev);
-	if (class_dev-&gt;dev)
+	if (class_dev-&gt;dev) {
+		class_name = make_class_name(class_dev);
 		sysfs_create_link(&amp;class_dev-&gt;kobj,
 				  &amp;class_dev-&gt;dev-&gt;kobj, "device");
+		sysfs_create_link(&amp;class_dev-&gt;dev-&gt;kobj, &amp;class_dev-&gt;kobj,
+				  class_name);
+	}
 
 	/* notify any interfaces this device is now here */
 	if (parent) {
@@ -519,6 +542,7 @@ int class_device_add(struct class_device
 	if (error &amp;&amp; parent)
 		class_put(parent);
 	class_device_put(class_dev);
+	kfree(class_name);
 	return error;
 }
 
@@ -584,6 +608,7 @@ void class_device_del(struct class_devic
 {
 	struct class * parent = class_dev-&gt;class;
 	struct class_interface * class_intf;
+	char *class_name = NULL;
 
 	if (parent) {
 		down(&amp;parent-&gt;sem);
@@ -594,8 +619,11 @@ void class_device_del(struct class_devic
 		up(&amp;parent-&gt;sem);
 	}
 
-	if (class_dev-&gt;dev)
+	if (class_dev-&gt;dev) {
+		class_name = make_class_name(class_dev);
 		sysfs_remove_link(&amp;class_dev-&gt;kobj, "device");
+		sysfs_remove_link(&amp;class_dev-&gt;dev-&gt;kobj, class_name);
+	}
 	if (class_dev-&gt;devt_attr)
 		class_device_remove_file(class_dev, class_dev-&gt;devt_attr);
 	class_device_remove_attrs(class_dev);
@@ -605,6 +633,7 @@ void class_device_del(struct class_devic
 
 	if (parent)
 		class_put(parent);
+	kfree(class_name);
 }
 
 void class_device_unregister(struct class_device *class_dev)
--- gregkh-2.6.orig/drivers/usb/core/hcd.c	2005-08-17 23:26:55.000000000 -0700
+++ gregkh-2.6/drivers/usb/core/hcd.c	2005-08-17 23:27:04.000000000 -0700
@@ -782,7 +782,7 @@ static int usb_register_bus(struct usb_b
 		return -E2BIG;
 	}
 
-	bus-&gt;class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus-&gt;controller, "usb%d", busnum);
+	bus-&gt;class_dev = class_device_create(usb_host_class, MKDEV(0,0), bus-&gt;controller, "usb_host%d", busnum);
 	if (IS_ERR(bus-&gt;class_dev)) {
 		clear_bit(busnum, busmap.busmap);
 		up(&amp;usb_bus_list_lock);
</pre></body></html>