提交 64bb5d2c 编写于 作者: G Greg Kroah-Hartman

Driver core: allow devices in classes to have no parent

This fixes an oops when a device is attached to a class, yet has no
"parent" device.  An example of this would be the "lo" device in the
network core.

We should create a "virtual" subdirectory under /sys/devices/ for these,
but no one seems to agree on a proper name for it yet...

Oh, and update my copyright on the driver core.
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 de0ff00d
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* *
* Copyright (c) 2002-3 Patrick Mochel * Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs * Copyright (c) 2002-3 Open Source Development Labs
* Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
* Copyright (c) 2006 Novell, Inc.
* *
* This file is released under the GPLv2 * This file is released under the GPLv2
* *
...@@ -373,10 +375,11 @@ int device_add(struct device *dev) ...@@ -373,10 +375,11 @@ int device_add(struct device *dev)
"subsystem"); "subsystem");
sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
dev->bus_id); dev->bus_id);
if (parent) {
sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
class_name = make_class_name(dev->class->name, &dev->kobj); class_name = make_class_name(dev->class->name, &dev->kobj);
sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
}
} }
if ((error = device_add_groups(dev))) if ((error = device_add_groups(dev)))
...@@ -495,8 +498,10 @@ void device_del(struct device * dev) ...@@ -495,8 +498,10 @@ void device_del(struct device * dev)
sysfs_remove_link(&dev->kobj, "subsystem"); sysfs_remove_link(&dev->kobj, "subsystem");
sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
class_name = make_class_name(dev->class->name, &dev->kobj); class_name = make_class_name(dev->class->name, &dev->kobj);
sysfs_remove_link(&dev->kobj, "device"); if (parent) {
sysfs_remove_link(&dev->parent->kobj, class_name); sysfs_remove_link(&dev->kobj, "device");
sysfs_remove_link(&dev->parent->kobj, class_name);
}
kfree(class_name); kfree(class_name);
down(&dev->class->sem); down(&dev->class->sem);
list_del_init(&dev->node); list_del_init(&dev->node);
...@@ -625,10 +630,6 @@ struct device *device_create(struct class *class, struct device *parent, ...@@ -625,10 +630,6 @@ struct device *device_create(struct class *class, struct device *parent,
if (class == NULL || IS_ERR(class)) if (class == NULL || IS_ERR(class))
goto error; goto error;
if (parent == NULL) {
printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__);
goto error;
}
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) { if (!dev) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册