]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
powerpc/cacheinfo: Fix kobject memleak
authorTobin C. Harding <tobin@kernel.org>
Tue, 30 Apr 2019 01:09:23 +0000 (11:09 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 1 May 2019 00:52:29 +0000 (10:52 +1000)
Currently error return from kobject_init_and_add() is not followed by
a call to kobject_put(). This means there is a memory leak.

Add call to kobject_put() in error path of kobject_init_and_add().

Signed-off-by: Tobin C. Harding <tobin@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/cacheinfo.c

index 53102764fd2f8f45d82dba2574e07365c3cca745..f2ed3ef4b129dd36a3b7d6030a7650cb2d9b7bf5 100644 (file)
@@ -759,23 +759,22 @@ static void cacheinfo_create_index_dir(struct cache *cache, int index,
 
        index_dir = kzalloc(sizeof(*index_dir), GFP_KERNEL);
        if (!index_dir)
-               goto err;
+               return;
 
        index_dir->cache = cache;
 
        rc = kobject_init_and_add(&index_dir->kobj, &cache_index_type,
                                  cache_dir->kobj, "index%d", index);
-       if (rc)
-               goto err;
+       if (rc) {
+               kobject_put(&index_dir->kobj);
+               kfree(index_dir);
+               return;
+       }
 
        index_dir->next = cache_dir->index;
        cache_dir->index = index_dir;
 
        cacheinfo_create_index_opt_attrs(index_dir);
-
-       return;
-err:
-       kfree(index_dir);
 }
 
 static void cacheinfo_sysfs_populate(unsigned int cpu_id,