[PATCH] erofs-utils: lib: fix error code loss in erofs_io_fallocate()

Utkal Singh singhutkal015 at gmail.com
Sun Mar 15 08:06:14 AEDT 2026


The final erofs_io_pwrite() call in erofs_io_fallocate() used a
ternary expression that discarded the real return value. If
erofs_io_pwrite() returned a negative error code such as -ENOSPC,
the caller would receive -EIO instead, losing the original error
information and making failures harder to diagnose.

Fix this by storing the return value in ret and propagating the
real error code directly, consistent with the loop above it.

Signed-off-by: Utkal Singh <singhutkal015 at gmail.com>
---
 lib/io.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/io.c b/lib/io.c
index 0c5eb2c..12a9beb 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -191,7 +191,10 @@ int erofs_io_fallocate(struct erofs_vfile *vf, u64 offset,
 		len -= ret;
 		offset += ret;
 	}
-	return erofs_io_pwrite(vf, erofs_zeroed, offset, len) == len ? 0 : -EIO;
+	ret = erofs_io_pwrite(vf, erofs_zeroed, offset, len);
+	if (ret != (ssize_t)len)
+		return ret < 0 ? (int)ret : -EIO;
+	return 0;
 }
 
 int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length)
-- 
2.43.0



More information about the Linux-erofs mailing list