diff mbox series

iomap: set did_zero to true when zeroing successfully

Message ID 1655198062-13288-1-git-send-email-kaixuxia@tencent.com (mailing list archive)
State Superseded
Headers show
Series iomap: set did_zero to true when zeroing successfully | expand

Commit Message

Kaixu Xia June 14, 2022, 9:14 a.m. UTC
From: Kaixu Xia <kaixuxia@tencent.com>

It is unnecessary to check and set did_zero value in while() loop,
we can set did_zero to true only when zeroing successfully at last.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
 fs/dax.c               | 4 ++--
 fs/iomap/buffered-io.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Chaitanya Kulkarni June 15, 2022, 10:07 p.m. UTC | #1
On 6/14/22 02:14, xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
> 
> It is unnecessary to check and set did_zero value in while() loop,
> we can set did_zero to true only when zeroing successfully at last.
> 
> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> ---

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
Christoph Hellwig June 16, 2022, 7:28 a.m. UTC | #2
On Tue, Jun 14, 2022 at 05:14:22PM +0800, xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
> 
> It is unnecessary to check and set did_zero value in while() loop,
> we can set did_zero to true only when zeroing successfully at last.

Looks good, but this really should be separate patches for dax and
iomap.
Kaixu Xia June 16, 2022, 11:14 a.m. UTC | #3
Christoph Hellwig <hch@infradead.org> 于2022年6月16日周四 15:28写道:
>
> On Tue, Jun 14, 2022 at 05:14:22PM +0800, xiakaixu1987@gmail.com wrote:
> > From: Kaixu Xia <kaixuxia@tencent.com>
> >
> > It is unnecessary to check and set did_zero value in while() loop,
> > we can set did_zero to true only when zeroing successfully at last.
>
> Looks good, but this really should be separate patches for dax and
> iomap.

Thanks for your suggestion, will separate it in V2.
diff mbox series

Patch

diff --git a/fs/dax.c b/fs/dax.c
index 4155a6107fa1..649ff51c9a26 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1088,10 +1088,10 @@  static s64 dax_zero_iter(struct iomap_iter *iter, bool *did_zero)
 		pos += size;
 		length -= size;
 		written += size;
-		if (did_zero)
-			*did_zero = true;
 	} while (length > 0);
 
+	if (did_zero)
+		*did_zero = true;
 	return written;
 }
 
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index d2a9f699e17e..1cadb24a1498 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -917,10 +917,10 @@  static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
 		pos += bytes;
 		length -= bytes;
 		written += bytes;
-		if (did_zero)
-			*did_zero = true;
 	} while (length > 0);
 
+	if (did_zero)
+		*did_zero = true;
 	return written;
 }