error: Eliminate error_propagate() with Coccinelle, part 2

When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away.  The previous commit did that with a Coccinelle script I
consider fairly trustworthy.  This commit uses the same script with
the matching of return taken out, i.e. we convert

    if (!foo(..., &err)) {
        ...
        error_propagate(errp, err);
        ...
    }

to

    if (!foo(..., errp)) {
        ...
        ...
    }

This is unsound: @err could still be read between afterwards.  I don't
know how to express "no read of @err without an intervening write" in
Coccinelle.  Instead, I manually double-checked for uses of @err.

Suboptimal line breaks tweaked manually.  qdev_realize() simplified
further to placate scripts/checkpatch.pl.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-36-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2020-07-07 18:06:03 +02:00
parent 668f62ec62
commit af175e85f9
23 changed files with 32 additions and 77 deletions

View file

@ -990,8 +990,7 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
encryptfmt = qdict_get_try_str(encryptopts, "format");
opts = qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort);
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
ret = -EINVAL;
goto fail;
}
@ -1595,8 +1594,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
/* read qcow2 extensions */
if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL,
flags, &update_header, &local_err)) {
error_propagate(errp, local_err);
flags, &update_header, errp)) {
ret = -EINVAL;
goto fail;
}
@ -3357,7 +3355,6 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
int version;
int refcount_order;
uint64_t* refcount_table;
Error *local_err = NULL;
int ret;
uint8_t compression_type = QCOW2_COMPRESSION_TYPE_ZLIB;
@ -3583,9 +3580,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
blk = blk_new_open(NULL, NULL, options,
BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
&local_err);
errp);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
goto out;
}
@ -3665,9 +3661,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
}
blk = blk_new_open(NULL, NULL, options,
BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
&local_err);
errp);
if (blk == NULL) {
error_propagate(errp, local_err);
ret = -EIO;
goto out;
}