public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: clean up the check in blkdev_iomap_begin()
@ 2024-06-25 11:55 linan666
  2024-06-27  3:44 ` Chaitanya Kulkarni
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: linan666 @ 2024-06-25 11:55 UTC (permalink / raw)
  To: axboe
  Cc: linux-block, linux-kernel, hch, linan666, yukuai3, yi.zhang,
	houtao1, yangerkun

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: clean up the check in blkdev_iomap_begin()
  2024-06-25 11:55 [PATCH] block: clean up the check in blkdev_iomap_begin() linan666
@ 2024-06-27  3:44 ` Chaitanya Kulkarni
  2024-06-27  4:54 ` Christoph Hellwig
  2024-06-27 15:55 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2024-06-27  3:44 UTC (permalink / raw)
  To: linan666@huaweicloud.com
  Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	hch@lst.de, yukuai3@huawei.com, yi.zhang@huawei.com,
	houtao1@huawei.com, yangerkun@huawei.com, axboe@kernel.dk

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: clean up the check in blkdev_iomap_begin()
  2024-06-25 11:55 [PATCH] block: clean up the check in blkdev_iomap_begin() linan666
  2024-06-27  3:44 ` Chaitanya Kulkarni
@ 2024-06-27  4:54 ` Christoph Hellwig
  2024-06-27 15:55 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2024-06-27  4:54 UTC (permalink / raw)
  To: linan666
  Cc: axboe, linux-block, linux-kernel, hch, yukuai3, yi.zhang, houtao1,
	yangerkun

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: clean up the check in blkdev_iomap_begin()
  2024-06-25 11:55 [PATCH] block: clean up the check in blkdev_iomap_begin() linan666
  2024-06-27  3:44 ` Chaitanya Kulkarni
  2024-06-27  4:54 ` Christoph Hellwig
@ 2024-06-27 15:55 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2024-06-27 15:55 UTC (permalink / raw)
  To: linan666
  Cc: linux-block, linux-kernel, hch, yukuai3, yi.zhang, houtao1,
	yangerkun


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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-27 15:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-25 11:55 [PATCH] block: clean up the check in blkdev_iomap_begin() linan666
2024-06-27  3:44 ` Chaitanya Kulkarni
2024-06-27  4:54 ` Christoph Hellwig
2024-06-27 15:55 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox