qemu-option: Use returned bool to check for failure

The previous commit enables conversion of

    foo(..., &err);
    if (err) {
        ...
    }

to

    if (!foo(..., &err)) {
        ...
    }

for QemuOpts functions that now return true / false on success /
error.  Coccinelle script:

    @@
    identifier fun = {
        opts_do_parse, parse_option_bool, parse_option_number,
        parse_option_size, qemu_opt_parse, qemu_opt_rename, qemu_opt_set,
        qemu_opt_set_bool, qemu_opt_set_number, qemu_opts_absorb_qdict,
        qemu_opts_do_parse, qemu_opts_from_qdict_entry, qemu_opts_set,
        qemu_opts_validate
    };
    expression list args, args2;
    typedef Error;
    Error *err;
    @@
    -    fun(args, &err, args2);
    -    if (err)
    +    if (!fun(args, &err, args2))
         {
             ...
         }

A few line breaks tidied up manually.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-15-armbru@redhat.com>
[Conflict with commit 0b6786a9c1 "block/amend: refactor qcow2 amend
options" resolved by rerunning Coccinelle on master's version]
This commit is contained in:
Markus Armbruster 2020-07-07 18:05:42 +02:00
parent c75d7f7191
commit 235e59cf03
32 changed files with 71 additions and 133 deletions

View file

@ -339,8 +339,7 @@ int qemu_set_option(const char *str)
return -1;
}
qemu_opt_set(opts, arg, str + offset + 1, &local_err);
if (local_err) {
if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) {
error_report_err(local_err);
return -1;
}
@ -441,8 +440,7 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
error_report("no group defined");
goto out;
}
qemu_opt_set(opts, arg, value, &local_err);
if (local_err) {
if (!qemu_opt_set(opts, arg, value, &local_err)) {
error_report_err(local_err);
goto out;
}
@ -498,8 +496,7 @@ static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
goto out;
}
qemu_opts_absorb_qdict(subopts, subqdict, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(subopts, subqdict, &local_err)) {
error_propagate(errp, local_err);
goto out;
}
@ -543,8 +540,7 @@ static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
goto out;
}
qemu_opts_absorb_qdict(subopts, section, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(subopts, section, &local_err)) {
error_propagate(errp, local_err);
qemu_opts_del(subopts);
goto out;