Re: [PATCH 2/7] block/blkio: fix error return value on getlength()

Akihiko Odaki <[email protected]> Sun, 26 Jul 2026 16:36:54 +0900
Newsgroups org.kernel.vger.linux-cxl,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 2026/07/25 23:00, Marc-André Lureau wrote:
> Negative values should be return for errors.

Nit: s/return/returned/

> 
> 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;

Initializing a variable with a dummy value can suppress a useful 
warning. Replacing WITH_QEMU_LOCK_GUARD() with QEMU_LOCK_GUARD() will 
fix it without introducing a dummy value and also result in a bit 
simpler code.

Regards,
Akihiko Odaki

>   
>       WITH_QEMU_LOCK_GUARD(&s->blkio_lock) {
>           ret = blkio_get_uint64(s->blkio, "capacity", &capacity);
>       }
>       if (ret < 0) {
> -        return -ret;
> +        return ret;
>       }
>   
>       return capacity;
>