aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2006-06-28 19:19:58 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-09-26 00:08:38 -0400
commit64bb5d2c116478dba7501d2acf078ed74ba30c1f (patch)
treebd0f695cad51a0b9608d686ab2b0232a31d4b2ad /drivers/base
parentde0ff00d723fd821d372496e2c084805644aa5e1 (diff)
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: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/core.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 641c0c42bb48..5c91d0d81e78 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (c) 2002-3 Patrick Mochel 4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs 5 * Copyright (c) 2002-3 Open Source Development Labs
6 * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de>
7 * Copyright (c) 2006 Novell, Inc.
6 * 8 *
7 * This file is released under the GPLv2 9 * This file is released under the GPLv2
8 * 10 *
@@ -373,10 +375,11 @@ int device_add(struct device *dev)
373 "subsystem"); 375 "subsystem");
374 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, 376 sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj,
375 dev->bus_id); 377 dev->bus_id);
376 378 if (parent) {
377 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); 379 sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device");
378 class_name = make_class_name(dev->class->name, &dev->kobj); 380 class_name = make_class_name(dev->class->name, &dev->kobj);
379 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); 381 sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name);
382 }
380 } 383 }
381 384
382 if ((error = device_add_groups(dev))) 385 if ((error = device_add_groups(dev)))
@@ -495,8 +498,10 @@ void device_del(struct device * dev)
495 sysfs_remove_link(&dev->kobj, "subsystem"); 498 sysfs_remove_link(&dev->kobj, "subsystem");
496 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); 499 sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id);
497 class_name = make_class_name(dev->class->name, &dev->kobj); 500 class_name = make_class_name(dev->class->name, &dev->kobj);
498 sysfs_remove_link(&dev->kobj, "device"); 501 if (parent) {
499 sysfs_remove_link(&dev->parent->kobj, class_name); 502 sysfs_remove_link(&dev->kobj, "device");
503 sysfs_remove_link(&dev->parent->kobj, class_name);
504 }
500 kfree(class_name); 505 kfree(class_name);
501 down(&dev->class->sem); 506 down(&dev->class->sem);
502 list_del_init(&dev->node); 507 list_del_init(&dev->node);
@@ -625,10 +630,6 @@ struct device *device_create(struct class *class, struct device *parent,
625 630
626 if (class == NULL || IS_ERR(class)) 631 if (class == NULL || IS_ERR(class))
627 goto error; 632 goto error;
628 if (parent == NULL) {
629 printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__);
630 goto error;
631 }
632 633
633 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 634 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
634 if (!dev) { 635 if (!dev) {