From 4f01a757e75f2a3cab2bab89c4176498963946b9 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 18 Sep 2007 22:46:50 -0700 Subject: Driver core: fix deprectated sysfs structure for nested class devices Nested class devices used to have 'device' symlink point to a real (physical) device instead of a parent class device. When converting subsystems to struct device we need to keep doing what class devices did if CONFIG_SYSFS_DEPRECATED is Y, otherwise parts of udev break. Signed-off-by: Dmitry Torokhov Cc: Kay Sievers Acked-by: Greg KH Tested-by: Anssi Hannula Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/base/core.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'drivers/base/core.c') diff --git a/drivers/base/core.c b/drivers/base/core.c index e6738bcbe5a..6de33d7a29b 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -679,14 +679,26 @@ static int device_add_class_symlinks(struct device *dev) goto out_subsys; } if (dev->parent) { - error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, - "device"); - if (error) - goto out_busid; #ifdef CONFIG_SYSFS_DEPRECATED { - char * class_name = make_class_name(dev->class->name, - &dev->kobj); + struct device *parent = dev->parent; + char *class_name; + + /* + * In old sysfs stacked class devices had 'device' + * link pointing to real device instead of parent + */ + while (parent->class && !parent->bus && parent->parent) + parent = parent->parent; + + error = sysfs_create_link(&dev->kobj, + &parent->kobj, + "device"); + if (error) + goto out_busid; + + class_name = make_class_name(dev->class->name, + &dev->kobj); if (class_name) error = sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); @@ -694,6 +706,11 @@ static int device_add_class_symlinks(struct device *dev) if (error) goto out_device; } +#else + error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, + "device"); + if (error) + goto out_busid; #endif } return 0; -- cgit v1.2.3 From 5309809129ca3ab14f8bd5e5ef66c1b7686eb639 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 26 Sep 2007 09:16:21 -0700 Subject: Add explicit zeroing to "envp" array in device 'show' method As Stephen Hemminger says, this is a "belt and suspenders" patch that zeroes the envp array at allocation time, even though all the users should NULL-terminate it anyway (and we've hopefully fixed everybody that doesn't do that). And we'll apparently clean the whole envp thing up for 2.6.24 anyway. But let's just be robust, and do both this *and* make sure that all users are doing the right thing. Acked-by: Stephen Hemminger Acked-by: Greg Kroah-Hartman Signed-off-by: Linus Torvalds --- drivers/base/core.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/base/core.c') diff --git a/drivers/base/core.c b/drivers/base/core.c index 6de33d7a29b..67c92582d6e 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -284,6 +284,7 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, /* let the kset specific function add its keys */ pos = data; + memset(envp, 0, sizeof(envp)); retval = kset->uevent_ops->uevent(kset, &dev->kobj, envp, ARRAY_SIZE(envp), pos, PAGE_SIZE); -- cgit v1.2.3 From 3eb215de26e6e94bf5fed9cb77230c383b30e53b Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 7 Oct 2007 12:22:21 -0400 Subject: Driver core: fix SYSF_DEPRECATED breakage for nested classdevs We should only reparent to a class former class devices that form the base of class hierarchy. Nested devices should still grow from their real parents. Signed-off-by: Dmitry Torokhov Tested-by: Andrey Borzenkov Tested-by: Anssi Hannula Signed-off-by: Linus Torvalds --- drivers/base/core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'drivers/base/core.c') diff --git a/drivers/base/core.c b/drivers/base/core.c index 67c92582d6e..ec86d6fc236 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -586,9 +586,13 @@ void device_initialize(struct device *dev) static struct kobject * get_device_parent(struct device *dev, struct device *parent) { - /* Set the parent to the class, not the parent device */ - /* this keeps sysfs from having a symlink to make old udevs happy */ - if (dev->class) + /* + * Set the parent to the class, not the parent device + * for topmost devices in class hierarchy. + * This keeps sysfs from having a symlink to make old + * udevs happy + */ + if (dev->class && (!parent || parent->class != dev->class)) return &dev->class->subsys.kobj; else if (parent) return &parent->kobj; -- cgit v1.2.3