Skip to content

Commit

Permalink
lib : kobject: fix refcount imblance on kobject_rename
Browse files Browse the repository at this point in the history
the kobj refcount increased by kobject_get should be released before
error return, otherwise lead to a memory leak.

Signed-off-by: Lin Yi <teroincn@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Lin Yi authored and Greg Kroah-Hartman committed Jun 19, 2019
1 parent 5666d89 commit 122f8ec
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,10 @@ int kobject_rename(struct kobject *kobj, const char *new_name)
kobj = kobject_get(kobj);
if (!kobj)
return -EINVAL;
if (!kobj->parent)
if (!kobj->parent) {
kobject_put(kobj);
return -EINVAL;
}

devpath = kobject_get_path(kobj, GFP_KERNEL);
if (!devpath) {
Expand Down

0 comments on commit 122f8ec

Please sign in to comment.