btrfs: sysfs: Fix error path kobject memory leak
commit535dedd9063c6c0f9283e4446fbf4ad77b07cec7
authorTobin C. Harding <tobin@kernel.org>
Mon, 13 May 2019 03:39:11 +0000 (13 13:39 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 31 May 2019 13:47:12 +0000 (31 06:47 -0700)
tree36dfe883924ceecfa93cff7db4dd59b0a0ff1f35
parent763d209ec6fffbf508efdac6d53a8d3d84808adb
btrfs: sysfs: Fix error path kobject memory leak

commit 450ff8348808a89cc27436771aa05c2b90c0eef1 upstream.

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

Calling kobject_put() when kobject_init_and_add() fails drops the
refcount back to 0 and calls the ktype release method (which in turn
calls the percpu destroy and kfree).

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

Cc: stable@vger.kernel.org # v4.4+
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Tobin C. Harding <tobin@kernel.org>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/extent-tree.c