]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: be a bit more careful when setting mirror_num_ret in btrfs_map_block
authorChristoph Hellwig <hch@lst.de>
Tue, 27 Jun 2023 06:13:23 +0000 (08:13 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jul 2023 06:50:39 +0000 (08:50 +0200)
[ Upstream commit 4e7de35eb7d1a1d4f2dda15f39fbedd4798a0b8d ]

The mirror_num_ret is allowed to be NULL, although it has to be set when
smap is set.  Unfortunately that is not a well enough specifiable
invariant for static type checkers, so add a NULL check to make sure they
are fine.

Fixes: 03793cbbc80f ("btrfs: add fast path for single device io in __btrfs_map_block")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/volumes.c

index 7433ae929fdcb02efca40d374723567a82658027..2e0832d70406c7abbc86f4f0827051b5a963b218 100644 (file)
@@ -6595,11 +6595,13 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
                if (patch_the_first_stripe_for_dev_replace) {
                        smap->dev = dev_replace->tgtdev;
                        smap->physical = physical_to_patch_in_first_stripe;
-                       *mirror_num_ret = map->num_stripes + 1;
+                       if (mirror_num_ret)
+                               *mirror_num_ret = map->num_stripes + 1;
                } else {
                        set_io_stripe(smap, map, stripe_index, stripe_offset,
                                      stripe_nr);
-                       *mirror_num_ret = mirror_num;
+                       if (mirror_num_ret)
+                               *mirror_num_ret = mirror_num;
                }
                *bioc_ret = NULL;
                ret = 0;