mirror of
https://github.com/mii443/qemu.git
synced 2025-12-03 11:08:25 +00:00
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>
This commit is contained in:
12
iothread.c
12
iothread.c
@@ -244,13 +244,14 @@ static void iothread_set_poll_param(Object *obj, Visitor *v,
|
||||
int64_t value;
|
||||
|
||||
if (!visit_type_int64(v, name, &value, &local_err)) {
|
||||
goto out;
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value < 0) {
|
||||
error_setg(&local_err, "%s value must be in range [0, %"PRId64"]",
|
||||
error_setg(errp, "%s value must be in range [0, %" PRId64 "]",
|
||||
info->name, INT64_MAX);
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
|
||||
*field = value;
|
||||
@@ -260,11 +261,8 @@ static void iothread_set_poll_param(Object *obj, Visitor *v,
|
||||
iothread->poll_max_ns,
|
||||
iothread->poll_grow,
|
||||
iothread->poll_shrink,
|
||||
&local_err);
|
||||
errp);
|
||||
}
|
||||
|
||||
out:
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
|
||||
static void iothread_class_init(ObjectClass *klass, void *class_data)
|
||||
|
||||
Reference in New Issue
Block a user