[ Upstream commit b9fba67b3806e21b98bd5a98dc3921a8e9b42d61 ]

If a call to kobject_init_and_add() fails we should call kobject_put()
otherwise we leak memory.

Add call to kobject_put() in the error path of call to
kobject_init_and_add().  Please note, this has the side effect that the
release method is called if kobject_init_and_add() fails.

Link: http://lkml.kernel.org/r/20190513033458.2824-1-to...@kernel.org
Signed-off-by: Tobin C. Harding <to...@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Reviewed-by: Joseph Qi <joseph...@linux.alibaba.com>
Cc: Mark Fasheh <m...@fasheh.com>
Cc: Joel Becker <jl...@evilplan.org>
Cc: Junxiao Bi <junxiao...@oracle.com>
Cc: Changwei Ge <gechang...@live.cn>
Cc: Gang He <g...@suse.com>
Cc: Jun Piao <piao...@huawei.com>
Signed-off-by: Andrew Morton <a...@linux-foundation.org>
Signed-off-by: Linus Torvalds <torva...@linux-foundation.org>
Signed-off-by: Sasha Levin <sas...@kernel.org>
---
 fs/ocfs2/filecheck.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/ocfs2/filecheck.c b/fs/ocfs2/filecheck.c
index f65f2b2f594d..1906cc962c4d 100644
--- a/fs/ocfs2/filecheck.c
+++ b/fs/ocfs2/filecheck.c
@@ -193,6 +193,7 @@ int ocfs2_filecheck_create_sysfs(struct ocfs2_super *osb)
        ret = kobject_init_and_add(&entry->fs_kobj, &ocfs2_ktype_filecheck,
                                        NULL, "filecheck");
        if (ret) {
+               kobject_put(&entry->fs_kobj);
                kfree(fcheck);
                return ret;
        }
-- 
2.20.1



Reply via email to