On 09/25/2017 08:57 AM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com>
> ---
>  block/nbd-client.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 

> @@ -233,6 +231,7 @@ static int nbd_co_request(BlockDriverState *bs,
>  
>      assert(!qiov || request->type == NBD_CMD_WRITE ||
>             request->type == NBD_CMD_READ);
> +    assert(!qiov || request->len == iov_size(qiov->iov, qiov->niov));

Asserting !qiov twice in a row feels a bit odd, although I see why you
have to do it to prevent a NULL dereference.  Would this be any easier
to read as a single assertion:

assert(!qiov ||
       ((request->type == NBD_CMD_WRITE ||
         request->type == NBD_CMD_READ) &&
        request->len == iov_size(qiov->iov, qiov->niov)));

Or, as a conditional:

if (qiov) {
    assert(request->type == NBD_CMD_WRITE || request->type == NBD_CMD_READ);
    assert(request->len == iov_size(qiov->iov, qiov->niov));
} else {
    assert(request->type != NBD_CMD_WRITE && request->type != NBD_CMD_READ);
}

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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to