summaryrefslogtreecommitdiff
path: root/drivers/base
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-12-19 03:40:42 +0300
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-25 07:40:39 +0300
commit0f4dafc0563c6c49e17fe14b3f5f356e4c4b8806 (patch)
treef4ded2831853cb6ea328d15d72871db6f8c22610 /drivers/base
parent12e339ac6e31a34fe42396aec8fb1c0b43caf61e (diff)
downloadlinux-0f4dafc0563c6c49e17fe14b3f5f356e4c4b8806.tar.xz
Kobject: auto-cleanup on final unref
We save the current state in the object itself, so we can do proper cleanup when the last reference is dropped. If the initial reference is dropped, the object will be removed from sysfs if needed, if an "add" event was sent, "remove" will be send, and the allocated resources are released. This allows us to clean up some driver core usage as well as allowing us to do other such changes to the rest of the kernel. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/core.c32
1 files changed, 7 insertions, 25 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 675a719dcdd2..d5d542db96fd 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -576,8 +576,8 @@ static struct kobject *get_device_parent(struct device *dev,
/*
* If we have no parent, we live in "virtual".
- * Class-devices with a bus-device as parent, live
- * in a class-directory to prevent namespace collisions.
+ * Class-devices with a non class-device as parent, live
+ * in a "glue" directory to prevent namespace collisions.
*/
if (parent == NULL)
parent_kobj = virtual_device_parent(dev);
@@ -607,8 +607,7 @@ static struct kobject *get_device_parent(struct device *dev,
kobject_put(k);
return NULL;
}
- /* Do not emit a uevent, as it's not needed for this
- * "class glue" directory. */
+ /* do not emit an uevent for this simple "glue" directory */
return k;
}
@@ -619,30 +618,13 @@ static struct kobject *get_device_parent(struct device *dev,
static void cleanup_device_parent(struct device *dev)
{
- struct device *d;
- int other = 0;
+ struct kobject *glue_dir = dev->kobj.parent;
- if (!dev->class)
- return;
-
- /* see if we live in a parent class directory */
- if (dev->kobj.parent->kset != &dev->class->class_dirs)
+ /* see if we live in a "glue" directory */
+ if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
return;
- /* if we are the last child of our class, delete the directory */
- down(&dev->class->sem);
- list_for_each_entry(d, &dev->class->devices, node) {
- if (d == dev)
- continue;
- if (d->kobj.parent == dev->kobj.parent) {
- other = 1;
- break;
- }
- }
- if (!other)
- kobject_del(dev->kobj.parent);
- kobject_put(dev->kobj.parent);
- up(&dev->class->sem);
+ kobject_put(glue_dir);
}
#endif