driver core: fix namespace issue with devices assigned to classes

  - uses a kset in "struct class" to keep track of all directories
    belonging to this class
  - merges with the /sys/devices/virtual logic.
  - removes the namespace-dir if the last member of that class
    leaves the directory.

There may be locking or refcounting fixes left, I stopped when it seemed
to work with network and sound modules. :)

From: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

diff --git a/lib/kobject.c b/lib/kobject.c
index 057921c..f664551 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -488,13 +488,15 @@
 };
 
 /**
- *	kobject_add_dir - add sub directory of object.
+ *	kobject__kset_add_dir - add sub directory of object.
+ *	@kset:		kset the directory is belongs to.
  *	@parent:	object in which a directory is created.
  *	@name:	directory name.
  *
  *	Add a plain directory object as child of given object.
  */
-struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
+struct kobject *kobject_kset_add_dir(struct kset *kset,
+				     struct kobject *parent, const char *name)
 {
 	struct kobject *k;
 	int ret;
@@ -506,6 +508,7 @@
 	if (!k)
 		return NULL;
 
+	k->kset = kset;
 	k->parent = parent;
 	k->ktype = &dir_ktype;
 	kobject_set_name(k, name);
@@ -520,6 +523,11 @@
 	return k;
 }
 
+struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
+{
+	return kobject_kset_add_dir(NULL, parent, name);
+}
+
 /**
  *	kset_init - initialize a kset for use
  *	@k:	kset