Subject: [RFC][PATCH] Fix another namespace issue with devices assigned to classes

From: [email-masked] (Eric W. Biederman)
Date: Wed, 02 Jun 2010 17:53:12 -0700

In the last painful restructuring of sysfs we created started
creating class directories under normal devices so we could place
devices such as network devices directly under their the hardware
that implements them instead of in their class directories like
/sys/class/net/.  This creation of class directories avoids the
need to worry about namespace clonflicts if something is renamed.

A special exception was made for devices that were still placed
directly in their class directory.  Looking at how this interacts
with the wireless network devices it appears this special exception
is either completely unneeded or at least needs to be restricted to
a parent device with the same class as the child device.  Certainly
in the case of unrelated classes we very much have the possibility
of namespace classes and we should be creating the subdirectory.

Johannes this should fix your issue with mac80211_hwsim, where
the device symlink were not destroyed when the driver was removed.

Greg, Kay where does that parent->class check come into play?  Do
we need it at all?

> commit 864062457a2e444227bd368ca5f2a2b740de604f
> Author: Kay Sievers <[email-masked]>
> Date:   Wed Mar 14 03:25:56 2007 +0100
> 
>     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 <[email-masked]>
>     Signed-off-by: Greg Kroah-Hartman <[email-masked]>

Signed-off-by: "Eric W. Biederman" <[email-masked]>

---

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 9630fbd..3725f81 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -673,7 +673,7 @@ static struct kobject *get_device_parent(struct device *dev,
 		 */
 		if (parent == NULL)
 			parent_kobj = virtual_device_parent(dev);
-		else if (parent->class)
+		else if (parent->class == dev->class)
 			return &parent->kobj;
 		else
 			parent_kobj = &parent->kobj;