diff mbox series

block: clean up the check in blkdev_iomap_begin()

Message ID 20240625115517.1472120-1-linan666@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series block: clean up the check in blkdev_iomap_begin() | expand

Commit Message

Li Nan June 25, 2024, 11:55 a.m. UTC
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(-)

Comments

Chaitanya Kulkarni June 27, 2024, 3:44 a.m. UTC | #1
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
Christoph Hellwig June 27, 2024, 4:54 a.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Jens Axboe June 27, 2024, 3:55 p.m. UTC | #3
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,
diff mbox series

Patch

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;