Message ID | 20230627061324.85216-2-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] btrfs: be a bit more careful when setting mirror_num_ret in btrfs_map_block | expand |
On 2023/6/27 14:13, Christoph Hellwig wrote: > 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> > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > --- > fs/btrfs/volumes.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c > index a536d0e0e05566..0d386ed44279ce 100644 > --- a/fs/btrfs/volumes.c > +++ b/fs/btrfs/volumes.c > @@ -6406,7 +6406,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, > (op == BTRFS_MAP_READ || !dev_replace_is_ongoing || > !dev_replace->tgtdev)) { > 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; > goto out;
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a536d0e0e05566..0d386ed44279ce 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6406,7 +6406,8 @@ int btrfs_map_block(struct btrfs_fs_info *fs_info, enum btrfs_map_op op, (op == BTRFS_MAP_READ || !dev_replace_is_ongoing || !dev_replace->tgtdev)) { 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; goto out;
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> Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/btrfs/volumes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)