summaryrefslogtreecommitdiffstats
path: root/hw/acpi
diff options
context:
space:
mode:
authorMarkus Armbruster2020-07-07 18:06:01 +0200
committerMarkus Armbruster2020-07-10 15:18:08 +0200
commitdcfe480544eef72d666cb1695624449e2c22da2d (patch)
treeaaa611acd223064dd8ebc278d0998c2e3d29c080 /hw/acpi
parentqdev: Use returned bool to check for failure, Coccinelle part (diff)
downloadqemu-dcfe480544eef72d666cb1695624449e2c22da2d.tar.gz
qemu-dcfe480544eef72d666cb1695624449e2c22da2d.tar.xz
qemu-dcfe480544eef72d666cb1695624449e2c22da2d.zip
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>
Diffstat (limited to 'hw/acpi')
-rw-r--r--hw/acpi/core.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 45cbed49ab..8b240c3e09 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -257,13 +257,13 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
goto out;
}
if (hdrs->has_file == hdrs->has_data) {
- error_setg(&err, "'-acpitable' requires one of 'data' or 'file'");
+ error_setg(errp, "'-acpitable' requires one of 'data' or 'file'");
goto out;
}
pathnames = g_strsplit(hdrs->has_file ? hdrs->file : hdrs->data, ":", 0);
if (pathnames == NULL || pathnames[0] == NULL) {
- error_setg(&err, "'-acpitable' requires at least one pathname");
+ error_setg(errp, "'-acpitable' requires at least one pathname");
goto out;
}
@@ -272,7 +272,7 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
int fd = open(*cur, O_RDONLY | O_BINARY);
if (fd < 0) {
- error_setg(&err, "can't open file %s: %s", *cur, strerror(errno));
+ error_setg(errp, "can't open file %s: %s", *cur, strerror(errno));
goto out;
}
@@ -288,8 +288,8 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
memcpy(blob + bloblen, data, r);
bloblen += r;
} else if (errno != EINTR) {
- error_setg(&err, "can't read file %s: %s",
- *cur, strerror(errno));
+ error_setg(errp, "can't read file %s: %s", *cur,
+ strerror(errno));
close(fd);
goto out;
}
@@ -298,14 +298,12 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
close(fd);
}
- acpi_table_install(blob, bloblen, hdrs->has_file, hdrs, &err);
+ acpi_table_install(blob, bloblen, hdrs->has_file, hdrs, errp);
out:
g_free(blob);
g_strfreev(pathnames);
qapi_free_AcpiTableOptions(hdrs);
-
- error_propagate(errp, err);
}
unsigned acpi_table_len(void *current)