diff mbox series

iomap: Fix error handling in iomap_zero_iter()

Message ID 20211221044450.517558-1-willy@infradead.org (mailing list archive)
State Accepted
Commit 9e05e95ca8dae8de4a7a1645014e1bbd9c8a4dab
Headers show
Series iomap: Fix error handling in iomap_zero_iter() | expand

Commit Message

Matthew Wilcox Dec. 21, 2021, 4:44 a.m. UTC
iomap_write_end() does not return a negative errno to indicate an
error, but the number of bytes successfully copied.  It cannot return
an error today, so include a debugging assertion like the one in
iomap_unshare_iter().

Fixes: c6f40468657d ("fsdax: decouple zeroing from the iomap buffered I/O code")
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/iomap/buffered-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Dec. 21, 2021, 8:27 a.m. UTC | #1
On Tue, Dec 21, 2021 at 04:44:50AM +0000, Matthew Wilcox (Oracle) wrote:
> iomap_write_end() does not return a negative errno to indicate an
> error, but the number of bytes successfully copied.  It cannot return
> an error today, so include a debugging assertion like the one in
> iomap_unshare_iter().

Looks good:

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

Patch

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index f3176cf90351..955f51f94b3f 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -901,8 +901,8 @@  static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero)
 		mark_page_accessed(page);
 
 		bytes = iomap_write_end(iter, pos, bytes, bytes, page);
-		if (bytes < 0)
-			return bytes;
+		if (WARN_ON_ONCE(bytes == 0))
+			return -EIO;
 
 		pos += bytes;
 		length -= bytes;