On Thu, 2008-04-17 at 21:59 -0700, Dan Williams wrote:
This could work, yes. We could just set a flag in the class, that
prevents the device entries in /sys/dev/.
The usual case is that one of the duplicated /sys devices is deprecated,
so it should be fine, to always point to the new one.
We will find a solution. :)
The following should work for the common case.
Best,
Kay
From: Kay Sievers <kay.sievers@vrfy.org>
Subject: sysfs: fix duplicated device number registration in /sys/dev/
If the parent device has the same dev_t, we skip the registration
for the device number at /sys/dev.
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
---
core.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index de925f8..afedadb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -821,10 +821,13 @@ int device_add(struct device *dev)
if (error)
goto ueventattrError;
- format_dev_t(devt_str, dev->devt);
- error = sysfs_create_link(kobj, &dev->kobj, devt_str);
- if (error)
- goto devtattrError;
+ /* do not create /sys/dev/ entry if parent already did */
+ if (!(dev->parent && dev->parent->devt == dev->devt)) {
+ format_dev_t(devt_str, dev->devt);
+ error = sysfs_create_link(kobj, &dev->kobj, devt_str);
+ if (error)
+ goto devtattrError;
+ }
}
error = device_add_class_symlinks(dev);
@@ -950,8 +953,10 @@ void device_del(struct device *dev)
if (parent)
klist_del(&dev->knode_parent);
if (MAJOR(dev->devt)) {
- format_dev_t(devt_str, dev->devt);
- sysfs_remove_link(device_to_dev_kobj(dev), devt_str);
+ if (!(parent && parent->devt == dev->devt)) {
+ format_dev_t(devt_str, dev->devt);
+ sysfs_remove_link(device_to_dev_kobj(dev), devt_str);
+ }
device_remove_file(dev, &devt_attr);
}
if (dev->class) {
--