mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06: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:
parent
0c0e618d23
commit
dcfe480544
24 changed files with 169 additions and 242 deletions
|
@ -44,24 +44,24 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
|
|||
&error_abort);
|
||||
if ((slot < 0 || slot >= machine->ram_slots) &&
|
||||
slot != PC_DIMM_UNASSIGNED_SLOT) {
|
||||
error_setg(&local_err, "invalid slot number %d, valid range is [0-%"
|
||||
PRIu64 "]", slot, machine->ram_slots - 1);
|
||||
goto out;
|
||||
error_setg(errp,
|
||||
"invalid slot number %d, valid range is [0-%" PRIu64 "]",
|
||||
slot, machine->ram_slots - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
slot = pc_dimm_get_free_slot(slot == PC_DIMM_UNASSIGNED_SLOT ? NULL : &slot,
|
||||
machine->ram_slots, &local_err);
|
||||
if (local_err) {
|
||||
goto out;
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
object_property_set_int(OBJECT(dimm), PC_DIMM_SLOT_PROP, slot,
|
||||
&error_abort);
|
||||
trace_mhp_pc_dimm_assigned_slot(slot);
|
||||
|
||||
memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
|
||||
&local_err);
|
||||
out:
|
||||
error_propagate(errp, local_err);
|
||||
errp);
|
||||
}
|
||||
|
||||
void pc_dimm_plug(PCDIMMDevice *dimm, MachineState *machine, Error **errp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue