@@ -369,17 +369,15 @@ static void ich9_pm_get_disable_s3(Object *obj, Visitor *v, const char *name,
static void ich9_pm_set_disable_s3(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
ICH9LPCPMRegs *pm = opaque;
- Error *local_err = NULL;
uint8_t value;
- visit_type_uint8(v, name, &value, &local_err);
- if (local_err) {
- goto out;
+ visit_type_uint8(v, name, &value, errp);
+ if (*errp) {
+ return;
}
pm->disable_s3 = value;
-out:
- error_propagate(errp, local_err);
}
static void ich9_pm_get_disable_s4(Object *obj, Visitor *v, const char *name,
@@ -394,17 +392,15 @@ static void ich9_pm_get_disable_s4(Object *obj, Visitor *v, const char *name,
static void ich9_pm_set_disable_s4(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
ICH9LPCPMRegs *pm = opaque;
- Error *local_err = NULL;
uint8_t value;
- visit_type_uint8(v, name, &value, &local_err);
- if (local_err) {
- goto out;
+ visit_type_uint8(v, name, &value, errp);
+ if (*errp) {
+ return;
}
pm->disable_s4 = value;
-out:
- error_propagate(errp, local_err);
}
static void ich9_pm_get_s4_val(Object *obj, Visitor *v, const char *name,
@@ -419,17 +415,15 @@ static void ich9_pm_get_s4_val(Object *obj, Visitor *v, const char *name,
static void ich9_pm_set_s4_val(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
ICH9LPCPMRegs *pm = opaque;
- Error *local_err = NULL;
uint8_t value;
- visit_type_uint8(v, name, &value, &local_err);
- if (local_err) {
- goto out;
+ visit_type_uint8(v, name, &value, errp);
+ if (*errp) {
+ return;
}
pm->s4_val = value;
-out:
- error_propagate(errp, local_err);
}
static bool ich9_pm_get_enable_tco(Object *obj, Error **errp)
@@ -97,14 +97,13 @@ static void debugcon_realize_core(DebugconState *s, Error **errp)
static void debugcon_isa_realizefn(DeviceState *dev, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
ISADevice *d = ISA_DEVICE(dev);
ISADebugconState *isa = ISA_DEBUGCON_DEVICE(dev);
DebugconState *s = &isa->state;
- Error *err = NULL;
- debugcon_realize_core(s, &err);
- if (err != NULL) {
- error_propagate(errp, err);
+ debugcon_realize_core(s, errp);
+ if (*errp) {
return;
}
memory_region_init_io(&s->io, OBJECT(dev), &debugcon_ops, s,
@@ -79,10 +79,10 @@ static void multi_serial_irq_mux(void *opaque, int n, int level)
static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
SerialState *s;
- Error *err = NULL;
int i, nr_ports = 0;
switch (pc->device_id) {
@@ -106,9 +106,8 @@ static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
for (i = 0; i < nr_ports; i++) {
s = pci->state + i;
s->baudbase = 115200;
- serial_realize_core(s, &err);
- if (err != NULL) {
- error_propagate(errp, err);
+ serial_realize_core(s, errp);
+ if (*errp) {
multi_serial_pci_exit(dev);
return;
}
@@ -43,14 +43,13 @@ typedef struct PCISerialState {
static void serial_pci_realize(PCIDevice *dev, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
PCISerialState *pci = DO_UPCAST(PCISerialState, dev, dev);
SerialState *s = &pci->state;
- Error *err = NULL;
s->baudbase = 115200;
- serial_realize_core(s, &err);
- if (err != NULL) {
- error_propagate(errp, err);
+ serial_realize_core(s, errp);
+ if (*errp) {
return;
}
@@ -192,13 +192,12 @@ static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
- Error *err = NULL;
+ ERRP_AUTO_PROPAGATE();
MachineState *ms = MACHINE(obj);
OnOffSplit mode;
- visit_type_OnOffSplit(v, name, &mode, &err);
- if (err) {
- error_propagate(errp, err);
+ visit_type_OnOffSplit(v, name, &mode, errp);
+ if (*errp) {
return;
} else {
switch (mode) {
@@ -240,13 +239,12 @@ static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
MachineState *ms = MACHINE(obj);
- Error *error = NULL;
int64_t value;
- visit_type_int(v, name, &value, &error);
- if (error) {
- error_propagate(errp, error);
+ visit_type_int(v, name, &value, errp);
+ if (*errp) {
return;
}
@@ -342,13 +340,12 @@ static void machine_set_phandle_start(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
MachineState *ms = MACHINE(obj);
- Error *error = NULL;
int64_t value;
- visit_type_int(v, name, &value, &error);
- if (error) {
- error_propagate(errp, error);
+ visit_type_int(v, name, &value, errp);
+ if (*errp) {
return;
}
@@ -59,7 +59,7 @@ static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
Error **errp)
{
- Error *err = NULL;
+ ERRP_AUTO_PROPAGATE();
uint16_t nodenr;
uint16List *cpus = NULL;
MachineClass *mc = MACHINE_GET_CLASS(ms);
@@ -99,9 +99,8 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
props = mc->cpu_index_to_instance_props(ms, cpus->value);
props.node_id = nodenr;
props.has_node_id = true;
- machine_set_cpu_numa_node(ms, &props, &err);
- if (err) {
- error_propagate(errp, err);
+ machine_set_cpu_numa_node(ms, &props, errp);
+ if (*errp) {
return;
}
}
@@ -177,60 +176,57 @@ void parse_numa_distance(MachineState *ms, NumaDistOptions *dist, Error **errp)
void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
{
- Error *err = NULL;
+ ERRP_AUTO_PROPAGATE();
MachineClass *mc = MACHINE_GET_CLASS(ms);
if (!mc->numa_mem_supported) {
error_setg(errp, "NUMA is not supported by this machine-type");
- goto end;
+ return;
}
switch (object->type) {
case NUMA_OPTIONS_TYPE_NODE:
- parse_numa_node(ms, &object->u.node, &err);
- if (err) {
- goto end;
+ parse_numa_node(ms, &object->u.node, errp);
+ if (*errp) {
+ return;
}
break;
case NUMA_OPTIONS_TYPE_DIST:
- parse_numa_distance(ms, &object->u.dist, &err);
- if (err) {
- goto end;
+ parse_numa_distance(ms, &object->u.dist, errp);
+ if (*errp) {
+ return;
}
break;
case NUMA_OPTIONS_TYPE_CPU:
if (!object->u.cpu.has_node_id) {
- error_setg(&err, "Missing mandatory node-id property");
- goto end;
+ error_setg(errp, "Missing mandatory node-id property");
+ return;
}
if (!ms->numa_state->nodes[object->u.cpu.node_id].present) {
- error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
- "defined with -numa node,nodeid=ID before it's used with "
- "-numa cpu,node-id=ID", object->u.cpu.node_id);
- goto end;
+ error_setg(errp, "Invalid node-id=%" PRId64 ", NUMA node must be "
+ "defined with -numa node,nodeid=ID before it's used with "
+ "-numa cpu,node-id=ID", object->u.cpu.node_id);
+ return;
}
machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.cpu),
- &err);
+ errp);
break;
default:
abort();
}
-
-end:
- error_propagate(errp, err);
}
static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
NumaOptions *object = NULL;
MachineState *ms = MACHINE(opaque);
- Error *err = NULL;
Visitor *v = opts_visitor_new(opts);
- visit_type_NumaOptions(v, NULL, &object, &err);
+ visit_type_NumaOptions(v, NULL, &object, errp);
visit_free(v);
- if (err) {
+ if (*errp) {
goto end;
}
@@ -240,12 +236,11 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem);
}
- set_numa_options(ms, object, &err);
+ set_numa_options(ms, object, errp);
end:
qapi_free_NumaOptions(object);
- if (err) {
- error_propagate(errp, err);
+ if (*errp) {
return -1;
}
@@ -464,9 +464,9 @@ static void apic_common_get_id(Object *obj, Visitor *v, const char *name,
static void apic_common_set_id(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
APICCommonState *s = APIC_COMMON(obj);
DeviceState *dev = DEVICE(obj);
- Error *local_err = NULL;
uint32_t value;
if (dev->realized) {
@@ -474,9 +474,8 @@ static void apic_common_set_id(Object *obj, Visitor *v, const char *name,
return;
}
- visit_type_uint32(v, name, &value, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ visit_type_uint32(v, name, &value, errp);
+ if (*errp) {
return;
}
@@ -855,18 +855,17 @@ out:
static void igd_pt_i440fx_realize(PCIDevice *pci_dev, Error **errp)
{
+ ERRP_AUTO_PROPAGATE();
uint32_t val = 0;
int i, num;
int pos, len;
- Error *local_err = NULL;
num = ARRAY_SIZE(igd_host_bridge_infos);
for (i = 0; i < num; i++) {
pos = igd_host_bridge_infos[i].offset;
len = igd_host_bridge_infos[i].len;
- host_pci_config_read(pos, len, &val, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ host_pci_config_read(pos, len, &val, errp);
+ if (*errp) {
return;
}
pci_default_write_config(pci_dev, pos, val, len);
If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases. If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf <kwolf@redhat.com> Reported-by: Greg Kurz <groug@kaod.org> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> --- hw/acpi/ich9.c | 30 +++++++++------------- hw/char/debugcon.c | 7 +++--- hw/char/serial-pci-multi.c | 7 +++--- hw/char/serial-pci.c | 7 +++--- hw/core/machine.c | 21 +++++++--------- hw/core/numa.c | 51 +++++++++++++++++--------------------- hw/intc/apic_common.c | 7 +++--- hw/pci-host/piix.c | 7 +++--- 8 files changed, 59 insertions(+), 78 deletions(-)