[PATCH 2/7] block/blkio: fix error return value on getlength()
Marc-André Lureau <[email protected]> Sat, 25 Jul 2026 18:00:03 +0400
| Newsgroups | org.kernel.vger.linux-cxl,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
Negative values should be return for errors.
It also helps with GCC false-positives:
../block/blkio.c: In function ‘blkio_co_getlength’:
../block/blkio.c:943:8: error: ‘ret’ may be used uninitialized [-Werror=maybe-uninitialized]
943 | if (ret < 0) {
| ^
Fixes: fd66dbd424 ("blkio: add libblkio block driver")
Signed-off-by: Marc-André Lureau <[email protected]>
---
block/blkio.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blkio.c b/block/blkio.c
index fb8bec27d71a..d2ba2a4d58dc 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -935,13 +935,13 @@ static int64_t coroutine_fn blkio_co_getlength(BlockDriverState *bs)
{
BDRVBlkioState *s = bs->opaque;
uint64_t capacity;
- int ret;
+ int ret = -1;
WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
ret = blkio_get_uint64(s->blkio, "capacity", &capacity);
}
if (ret < 0) {
- return -ret;
+ return ret;
}
return capacity;
--
2.55.0