]> git.proxmox.com Git - mirror_qemu.git/commit
error: Avoid unnecessary error_propagate() after error_setg()
authorMarkus Armbruster <armbru@redhat.com>
Tue, 7 Jul 2020 16:06:01 +0000 (18:06 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Fri, 10 Jul 2020 13:18:08 +0000 (15:18 +0200)
commitdcfe480544eef72d666cb1695624449e2c22da2d
treeaaa611acd223064dd8ebc278d0998c2e3d29c080
parent0c0e618d233e3249f6b60678a1b013a2c8d83339
error: Avoid unnecessary error_propagate() after error_setg()

Replace

    error_setg(&err, ...);
    error_propagate(errp, err);

by

    error_setg(errp, ...);

Related pattern:

    if (...) {
        error_setg(&err, ...);
        goto out;
    }
    ...
 out:
    error_propagate(errp, err);
    return;

When all paths to label out are that way, replace by

    if (...) {
        error_setg(errp, ...);
        return;
    }

and delete the label along with the error_propagate().

When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.

    foo(..., &err);
    if (err) {
        goto out;
    }
    ...
    bar(..., &err);
 out:
    error_propagate(errp, err);
    return;

move the error_propagate() to where it's needed, like

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

and transform the error_setg() as above.

In some places, the transformation results in obviously unnecessary
error_propagate().  The next few commits will eliminate them.

Bonus: the elimination of gotos will make later patches in this series
easier to review.

Candidates for conversion tracked down with this Coccinelle script:

    @@
    identifier err, errp;
    expression list args;
    @@
    -    error_setg(&err, args);
    +    error_setg(errp, args);
         ... when != err
         error_propagate(errp, err);

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
24 files changed:
backends/cryptodev.c
backends/hostmem-file.c
backends/hostmem-memfd.c
backends/hostmem.c
block/quorum.c
block/replication.c
block/throttle-groups.c
block/vxhs.c
hw/acpi/core.c
hw/hyperv/vmbus.c
hw/i386/pc.c
hw/mem/nvdimm.c
hw/mem/pc-dimm.c
hw/misc/aspeed_sdmc.c
hw/ppc/rs6000_mc.c
hw/ppc/spapr.c
hw/ppc/spapr_pci.c
hw/s390x/ipl.c
hw/xen/xen_pt_config_init.c
iothread.c
net/colo-compare.c
net/dump.c
net/filter-buffer.c
qga/commands-win32.c