OSDN Git Service

lib : kobject: fix refcount imblance on kobject_rename
authorLin Yi <teroincn@163.com>
Mon, 3 Jun 2019 08:08:10 +0000 (16:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jun 2019 17:27:39 +0000 (19:27 +0200)
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>
lib/kobject.c

index f2ccdba..83198cb 100644 (file)
@@ -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) {