Skip to content

Commit

Permalink
Driver core: Fix cleanup when failing device_add().
Browse files Browse the repository at this point in the history
Driver core: Fix cleanup when failing device_add().

 - Don't call cleanup_device_parent() if we didn't call setup_parent().
 - dev->kobj.parent may be NULL when cleanup_device_parent() is called,
   so we need to handle glue_dir == NULL in cleanup_glue_dir().

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Cornelia Huck authored and Greg Kroah-Hartman committed Mar 4, 2008
1 parent 135dee0 commit c1fe539
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ static struct kobject *get_device_parent(struct device *dev,
static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
{
/* see if we live in a "glue" directory */
if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
if (!glue_dir || !dev->class ||
glue_dir->kset != &dev->class->class_dirs)
return;

kobject_put(glue_dir);
Expand Down Expand Up @@ -773,7 +774,7 @@ int device_add(struct device *dev)
dev = get_device(dev);
if (!dev || !strlen(dev->bus_id)) {
error = -EINVAL;
goto Error;
goto Done;
}

pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
Expand Down

0 comments on commit c1fe539

Please sign in to comment.