summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobin C. Harding <tobin@kernel.org>2019-05-13 13:39:11 +1000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-05-31 06:43:11 -0700
commitb2a48467bfdfa0a08ff8731241f54d59a4440748 (patch)
tree3b0e43e04903bd0b67e23c63b0d7f0cd27dcc3db
parentffd658adf684aa47b73229ab12b9adc8f4dc18f6 (diff)
downloadlinux-stable-b2a48467bfdfa0a08ff8731241f54d59a4440748.tar.gz
linux-stable-b2a48467bfdfa0a08ff8731241f54d59a4440748.tar.bz2
linux-stable-b2a48467bfdfa0a08ff8731241f54d59a4440748.zip
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>
-rw-r--r--fs/btrfs/extent-tree.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d789542edc5a..c52967c29d77 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3981,8 +3981,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags)
info->space_info_kobj, "%s",
alloc_name(space_info->flags));
if (ret) {
- percpu_counter_destroy(&space_info->total_bytes_pinned);
- kfree(space_info);
+ kobject_put(&space_info->kobj);
return ret;
}