qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success


From: Eric Blake
Subject: Re: [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success
Date: Wed, 18 May 2022 07:57:29 -0500
User-agent: NeoMutt/20220429-71-6f7d3e

On Tue, May 17, 2022 at 12:35:07PM +0100, Alberto Faria wrote:
> They currently return the value of their 'bytes' parameter on success.
> 
> Make them return 0 instead, for consistency with other I/O functions and
> in preparation to implement them using generated_co_wrapper. This also
> makes it clear that short reads/writes are not possible.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---

> +++ b/qemu-img.c
> @@ -5120,30 +5120,27 @@ static int img_dd(int argc, char **argv)
>      in.buf = g_new(uint8_t, in.bsz);
>  
>      for (out_pos = 0; in_pos < size; block_count++) {

in_pos, out_pos, and size are int64_t...

> -        int in_ret, out_ret;
> +        int bytes, in_ret, out_ret;
>  
> -        if (in_pos + in.bsz > size) {
> -            in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos);
> -        } else {
> -            in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz);
> -        }
> +        bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;

...but in.bsz is int, so declaring 'int bytes' appears safe.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]