Skip to content

Commit

Permalink
driver core: fix device_create() error path
Browse files Browse the repository at this point in the history
We call put_device() in the error path, which is fine for dev==NULL.
However, in case kobject_set_name_vargs() fails, we have dev!=NULL but
device_initialized() wasn't called, yet.

Fix this by splitting device_register() into explicit calls to
device_add() and an early call to device_initialize().

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
David Herrmann authored and Greg Kroah-Hartman committed Dec 9, 2013
1 parent d0f80f9 commit bbc780f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ device_create_groups_vargs(struct class *class, struct device *parent,
goto error;
}

device_initialize(dev);
dev->devt = devt;
dev->class = class;
dev->parent = parent;
Expand All @@ -1614,7 +1615,7 @@ device_create_groups_vargs(struct class *class, struct device *parent,
if (retval)
goto error;

retval = device_register(dev);
retval = device_add(dev);
if (retval)
goto error;

Expand Down

0 comments on commit bbc780f

Please sign in to comment.