aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/core.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d5d542db96fd..f09dde3b1e27 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -552,6 +552,8 @@ static struct kobject *get_device_parent(struct device *dev,
552} 552}
553 553
554static inline void cleanup_device_parent(struct device *dev) {} 554static inline void cleanup_device_parent(struct device *dev) {}
555static inline void cleanup_glue_dir(struct device *dev,
556 struct kobject *glue_dir) {}
555#else 557#else
556static struct kobject *virtual_device_parent(struct device *dev) 558static struct kobject *virtual_device_parent(struct device *dev)
557{ 559{
@@ -616,27 +618,27 @@ static struct kobject *get_device_parent(struct device *dev,
616 return NULL; 618 return NULL;
617} 619}
618 620
619static void cleanup_device_parent(struct device *dev) 621static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
620{ 622{
621 struct kobject *glue_dir = dev->kobj.parent;
622
623 /* see if we live in a "glue" directory */ 623 /* see if we live in a "glue" directory */
624 if (!dev->class || glue_dir->kset != &dev->class->class_dirs) 624 if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
625 return; 625 return;
626 626
627 kobject_put(glue_dir); 627 kobject_put(glue_dir);
628} 628}
629
630static void cleanup_device_parent(struct device *dev)
631{
632 cleanup_glue_dir(dev, dev->kobj.parent);
633}
629#endif 634#endif
630 635
631static int setup_parent(struct device *dev, struct device *parent) 636static void setup_parent(struct device *dev, struct device *parent)
632{ 637{
633 struct kobject *kobj; 638 struct kobject *kobj;
634 kobj = get_device_parent(dev, parent); 639 kobj = get_device_parent(dev, parent);
635 if (IS_ERR(kobj))
636 return PTR_ERR(kobj);
637 if (kobj) 640 if (kobj)
638 dev->kobj.parent = kobj; 641 dev->kobj.parent = kobj;
639 return 0;
640} 642}
641 643
642static int device_add_class_symlinks(struct device *dev) 644static int device_add_class_symlinks(struct device *dev)
@@ -784,9 +786,7 @@ int device_add(struct device *dev)
784 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); 786 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
785 787
786 parent = get_device(dev->parent); 788 parent = get_device(dev->parent);
787 error = setup_parent(dev, parent); 789 setup_parent(dev, parent);
788 if (error)
789 goto Error;
790 790
791 /* first, register with generic layer. */ 791 /* first, register with generic layer. */
792 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); 792 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
@@ -864,6 +864,7 @@ int device_add(struct device *dev)
864 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 864 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
865 kobject_del(&dev->kobj); 865 kobject_del(&dev->kobj);
866 Error: 866 Error:
867 cleanup_device_parent(dev);
867 if (parent) 868 if (parent)
868 put_device(parent); 869 put_device(parent);
869 goto Done; 870 goto Done;
@@ -1344,15 +1345,12 @@ int device_move(struct device *dev, struct device *new_parent)
1344 1345
1345 new_parent = get_device(new_parent); 1346 new_parent = get_device(new_parent);
1346 new_parent_kobj = get_device_parent (dev, new_parent); 1347 new_parent_kobj = get_device_parent (dev, new_parent);
1347 if (IS_ERR(new_parent_kobj)) { 1348
1348 error = PTR_ERR(new_parent_kobj);
1349 put_device(new_parent);
1350 goto out;
1351 }
1352 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, 1349 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
1353 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>"); 1350 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
1354 error = kobject_move(&dev->kobj, new_parent_kobj); 1351 error = kobject_move(&dev->kobj, new_parent_kobj);
1355 if (error) { 1352 if (error) {
1353 cleanup_glue_dir(dev, new_parent_kobj);
1356 put_device(new_parent); 1354 put_device(new_parent);
1357 goto out; 1355 goto out;
1358 } 1356 }
@@ -1375,6 +1373,7 @@ int device_move(struct device *dev, struct device *new_parent)
1375 klist_add_tail(&dev->knode_parent, 1373 klist_add_tail(&dev->knode_parent,
1376 &old_parent->klist_children); 1374 &old_parent->klist_children);
1377 } 1375 }
1376 cleanup_glue_dir(dev, new_parent_kobj);
1378 put_device(new_parent); 1377 put_device(new_parent);
1379 goto out; 1378 goto out;
1380 } 1379 }