block/fops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
From: Li Nan <linan122@huawei.com>
It is odd to check the offset amidst a series of assignments. Moving this
check to the beginning of the function makes the code look better.
Signed-off-by: Li Nan <linan122@huawei.com>
---
block/fops.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/block/fops.c b/block/fops.c
index 376265935714..bc5ad3e6197f 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -383,10 +383,11 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
struct block_device *bdev = I_BDEV(inode);
loff_t isize = i_size_read(inode);
- iomap->bdev = bdev;
- iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev));
if (offset >= isize)
return -EIO;
+
+ iomap->bdev = bdev;
+ iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev));
iomap->type = IOMAP_MAPPED;
iomap->addr = iomap->offset;
iomap->length = isize - iomap->offset;
--
2.39.2
On Tue, 25 Jun 2024 19:55:17 +0800, linan666@huaweicloud.com wrote:
> It is odd to check the offset amidst a series of assignments. Moving this
> check to the beginning of the function makes the code look better.
>
>
Applied, thanks!
[1/1] block: clean up the check in blkdev_iomap_begin()
commit: e269537e491da6336776b5548a3c73f62273aa15
Best regards,
--
Jens Axboe
Looks good: Reviewed-by: Christoph Hellwig <hch@lst.de>
On 6/25/24 04:55, linan666@huaweicloud.com wrote: > From: Li Nan<linan122@huawei.com> > > It is odd to check the offset amidst a series of assignments. Moving this > check to the beginning of the function makes the code look better. > > Signed-off-by: Li Nan<linan122@huawei.com> it is always better to wait for assignments after all the error checks. I believe you have verified all the callers and make sure none of the callers rely on these assignments when this function returns -EIO and this change will not result in change of behavior, if that is the case :- Looks good. Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> -ck
© 2016 - 2025 Red Hat, Inc.