diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-07-07 18:06:01 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-07-10 15:18:08 +0200 |
commit | dcfe480544eef72d666cb1695624449e2c22da2d (patch) | |
tree | aaa611acd223064dd8ebc278d0998c2e3d29c080 /block/vxhs.c | |
parent | 0c0e618d233e3249f6b60678a1b013a2c8d83339 (diff) |
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 'block/vxhs.c')
-rw-r--r-- | block/vxhs.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/block/vxhs.c b/block/vxhs.c index 237df4f185..fecaeb82c9 100644 --- a/block/vxhs.c +++ b/block/vxhs.c @@ -326,14 +326,14 @@ static int vxhs_open(BlockDriverState *bs, QDict *options, /* vdisk-id is the disk UUID */ vdisk_id_opt = qemu_opt_get(opts, VXHS_OPT_VDISK_ID); if (!vdisk_id_opt) { - error_setg(&local_err, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID); + error_setg(errp, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID); ret = -EINVAL; goto out; } /* vdisk-id may contain a leading '/' */ if (strlen(vdisk_id_opt) > UUID_FMT_LEN + 1) { - error_setg(&local_err, "vdisk-id cannot be more than %d characters", + error_setg(errp, "vdisk-id cannot be more than %d characters", UUID_FMT_LEN); ret = -EINVAL; goto out; @@ -352,14 +352,14 @@ static int vxhs_open(BlockDriverState *bs, QDict *options, server_host_opt = qemu_opt_get(tcp_opts, VXHS_OPT_HOST); if (!server_host_opt) { - error_setg(&local_err, QERR_MISSING_PARAMETER, + error_setg(errp, QERR_MISSING_PARAMETER, VXHS_OPT_SERVER"."VXHS_OPT_HOST); ret = -EINVAL; goto out; } if (strlen(server_host_opt) > MAXHOSTNAMELEN) { - error_setg(&local_err, "server.host cannot be more than %d characters", + error_setg(errp, "server.host cannot be more than %d characters", MAXHOSTNAMELEN); ret = -EINVAL; goto out; @@ -412,7 +412,6 @@ out: if (ret < 0) { vxhs_unref(); - error_propagate(errp, local_err); g_free(s->vdisk_hostinfo.host); g_free(s->vdisk_guid); g_free(s->tlscredsid); |