diff mbox series

btrfs: fix smatch static checker warning in btrfs_scan_one_device

Message ID 81fd5fbda9772cde786d60b3cecf7d60d5a378f0.1694765532.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fix smatch static checker warning in btrfs_scan_one_device | expand

Commit Message

Anand Jain Sept. 15, 2023, 8:17 a.m. UTC
Commit d41f57d15a90 ("btrfs: scan but don't register device on
single device filesystem") might call btrfs_free_stale_devices() with
uninitialized devt.

To fix bring the btrfs_free_stale_devices() under the else part which
will ensure devt is initialized.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/linux-btrfs/32e15558-0a3f-418a-b3ae-8cfbddbff7af@moroto.mountain
Fixes: d41f57d15a90 ("btrfs: scan but don't register device on single device filesystem")
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---

David,

  Could you pls fold this fix into the commit d41f57d15a90 ("btrfs: scan
  but don't register device on single device filesystem")

Thx.

 fs/btrfs/volumes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

David Sterba Sept. 15, 2023, 2:34 p.m. UTC | #1
On Fri, Sep 15, 2023 at 04:17:21PM +0800, Anand Jain wrote:
> Commit d41f57d15a90 ("btrfs: scan but don't register device on
> single device filesystem") might call btrfs_free_stale_devices() with
> uninitialized devt.
> 
> To fix bring the btrfs_free_stale_devices() under the else part which
> will ensure devt is initialized.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Link: https://lore.kernel.org/linux-btrfs/32e15558-0a3f-418a-b3ae-8cfbddbff7af@moroto.mountain
> Fixes: d41f57d15a90 ("btrfs: scan but don't register device on single device filesystem")
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> 
> David,
> 
>   Could you pls fold this fix into the commit d41f57d15a90 ("btrfs: scan
>   but don't register device on single device filesystem")

Folded, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 47c1fa3f24e3..289cec740c2d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1280,11 +1280,11 @@  struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags,
 		dev_t	devt;
 
 		ret = lookup_bdev(path, &devt);
-		if (ret) {
+		if (ret)
 			btrfs_warn(NULL, "lookup bdev failed for path %s: %d",
 			path, ret);
-		}
-		btrfs_free_stale_devices(devt, NULL);
+		else
+			btrfs_free_stale_devices(devt, NULL);
 
 		pr_debug("BTRFS (%s) skip registering single non seed device\n",
 			 path);