From: Dan Carpenter <dan.carpenter@linaro.org>
Date: Wed, 26 Jul 2023 06:59:04 +0000 (+0300)
Subject: fs: btrfs: Prevent error pointer dereference in list_subvolums()
X-Git-Tag: v2025.01-rc5-pxa1908~847^2~40^2~12
X-Git-Url: http://git.dujemihanovic.xyz/%22http:/www.sics.se/static/html/%7B%7B%20%28.OutputFormats.Get?a=commitdiff_plain;h=c331efd08766aa610aa14c957856ef5b0fa915df;p=u-boot.git

fs: btrfs: Prevent error pointer dereference in list_subvolums()

If btrfs_read_fs_root() fails with -ENOENT, then we go to the next
entry.  Fine.  But if it fails for a different reason then we need
to clean up and return an error code.  In the current code it
doesn't clean up but instead dereferences "root" and crashes.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Marek BehĂșn <kabel@kernel.org>
Reviewed-by: Qu Wenruo <wqu@suse.com>
---

diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
index d446e7a2c4..68ca7e48e4 100644
--- a/fs/btrfs/subvolume.c
+++ b/fs/btrfs/subvolume.c
@@ -199,6 +199,7 @@ static int list_subvolums(struct btrfs_fs_info *fs_info)
 			ret = PTR_ERR(root);
 			if (ret == -ENOENT)
 				goto next;
+			goto out;
 		}
 		ret = list_one_subvol(root, result);
 		if (ret < 0)