fs/iomap/buffered-io.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 8ce8720093b9..eb1973792c68 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -758,13 +758,20 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) if (bytes > length) bytes = length; + /* Nobody _should_ call us with an empty iter, but.. */ + if (WARN_ON_ONCE(!bytes)) { + status = 0; + break; + } + /* * Bring in the user page that we'll copy from _first_. * Otherwise there's a nasty deadlock on copying from the * same page as we're writing to, without it being marked * up-to-date. */ - if (unlikely(fault_in_iov_iter_readable(i, bytes) == bytes)) { + bytes -= fault_in_iov_iter_readable(i, bytes); + if (unlikely(!bytes)) { status = -EFAULT; break; }