Skip to contentSkip to conversation

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

PATCH New Utkal Singh 1 participant 1 message Mar 14 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix error code loss in erofs_io_fallocate()

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.

---
 lib/io.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/io.c +4 -1
index 0c5eb2c..12a9beb 100644
@@ -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)
Signature · 1 line
2.43.0