error: Eliminate error_propagate() manually
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. The previous two commits did that for sufficiently simple
cases with Coccinelle. Do it for several more manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-37-armbru@redhat.com>
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index f22f46c..e9ed3ee 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2528,7 +2528,7 @@
FDrive *drive;
DeviceState *dev;
BlockBackend *blk;
- Error *local_err = NULL;
+ bool ok;
const char *fdc_name, *drive_suffix;
for (i = 0; i < MAX_FD; i++) {
@@ -2567,11 +2567,9 @@
blk_ref(blk);
blk_detach_dev(blk, fdc_dev);
fdctrl->qdev_for_drives[i].blk = NULL;
- qdev_prop_set_drive_err(dev, "drive", blk, &local_err);
+ ok = qdev_prop_set_drive_err(dev, "drive", blk, errp);
blk_unref(blk);
-
- if (local_err) {
- error_propagate(errp, local_err);
+ if (!ok) {
return;
}
diff --git a/hw/core/numa.c b/hw/core/numa.c
index de9a2f7..1b3267a 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -456,40 +456,33 @@
void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
{
- Error *err = NULL;
-
if (!ms->numa_state) {
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);
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);
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);
+ machine_set_cpu_numa_node(ms,
+ qapi_NumaCpuOptions_base(&object->u.cpu),
+ errp);
break;
case NUMA_OPTIONS_TYPE_HMAT_LB:
if (!ms->numa_state->hmat_enabled) {
@@ -499,10 +492,7 @@
return;
}
- parse_numa_hmat_lb(ms->numa_state, &object->u.hmat_lb, &err);
- if (err) {
- goto end;
- }
+ parse_numa_hmat_lb(ms->numa_state, &object->u.hmat_lb, errp);
break;
case NUMA_OPTIONS_TYPE_HMAT_CACHE:
if (!ms->numa_state->hmat_enabled) {
@@ -512,17 +502,11 @@
return;
}
- parse_numa_hmat_cache(ms, &object->u.hmat_cache, &err);
- if (err) {
- goto end;
- }
+ parse_numa_hmat_cache(ms, &object->u.hmat_cache, errp);
break;
default:
abort();
}
-
-end:
- error_propagate(errp, err);
}
static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 22b524e..67bee1b 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -118,17 +118,15 @@
void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)
{
- Error *local_err = NULL;
Object *cpu = object_new(MACHINE(x86ms)->cpu_type);
- if (!object_property_set_uint(cpu, "apic-id", apic_id, &local_err)) {
+ if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) {
goto out;
}
- qdev_realize(DEVICE(cpu), NULL, &local_err);
+ qdev_realize(DEVICE(cpu), NULL, errp);
out:
object_unref(cpu);
- error_propagate(errp, local_err);
}
void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
diff --git a/hw/intc/xive.c b/hw/intc/xive.c
index 3459165..9a16243 100644
--- a/hw/intc/xive.c
+++ b/hw/intc/xive.c
@@ -757,7 +757,6 @@
Object *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp)
{
- Error *local_err = NULL;
Object *obj;
obj = object_new(TYPE_XIVE_TCTX);
@@ -765,16 +764,11 @@
object_unref(obj);
object_property_set_link(obj, "cpu", cpu, &error_abort);
object_property_set_link(obj, "presenter", OBJECT(xptr), &error_abort);
- if (!qdev_realize(DEVICE(obj), NULL, &local_err)) {
- goto error;
+ if (!qdev_realize(DEVICE(obj), NULL, errp)) {
+ object_unparent(obj);
+ return NULL;
}
-
return obj;
-
-error:
- object_unparent(obj);
- error_propagate(errp, local_err);
- return NULL;
}
void xive_tctx_destroy(XiveTCTX *tctx)
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 85330d0..c4f47dc 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -239,8 +239,8 @@
CPUState *cs = CPU(cpu);
Error *local_err = NULL;
- if (!qdev_realize(DEVICE(cpu), NULL, &local_err)) {
- goto error;
+ if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
+ return;
}
/* Set time-base frequency to 512 MHz */
@@ -250,20 +250,14 @@
kvmppc_set_papr(cpu);
if (spapr_irq_cpu_intc_create(spapr, cpu, &local_err) < 0) {
- goto error_intc_create;
+ cpu_remove_sync(CPU(cpu));
+ return;
}
if (!sc->pre_3_0_migration) {
vmstate_register(NULL, cs->cpu_index, &vmstate_spapr_cpu_state,
cpu->machine_data);
}
-
- return;
-
-error_intc_create:
- cpu_remove_sync(CPU(cpu));
-error:
- error_propagate(errp, local_err);
}
static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp)
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 24de4ed..92146a2 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -743,7 +743,6 @@
BusState *bus;
PCIHostState *phb = PCI_HOST_BRIDGE(dev);
S390pciState *s = S390_PCI_HOST_BRIDGE(dev);
- Error *local_err = NULL;
DPRINTF("host_init\n");
@@ -767,8 +766,7 @@
QTAILQ_INIT(&s->zpci_devs);
css_register_io_adapters(CSS_IO_ADAPTER_PCI, true, false,
- S390_ADAPTER_SUPPRESSIBLE, &local_err);
- error_propagate(errp, local_err);
+ S390_ADAPTER_SUPPRESSIBLE, errp);
}
static int s390_pci_msix_init(S390PCIBusDevice *pbdev)
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 20e8e95..8cc2f25 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -68,20 +68,18 @@
Error **errp)
{
S390CPU *cpu = S390_CPU(object_new(typename));
- Error *err = NULL;
S390CPU *ret = NULL;
- if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, &err)) {
+ if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) {
goto out;
}
- if (!qdev_realize(DEVICE(cpu), NULL, &err)) {
+ if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
goto out;
}
ret = cpu;
out:
object_unref(OBJECT(cpu));
- error_propagate(errp, err);
return ret;
}
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 0336434..a0ce444 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -329,7 +329,6 @@
{
MachineState *machine = MACHINE(qdev_get_machine());
SCLPDevice *sclp = SCLP(dev);
- Error *err = NULL;
uint64_t hw_limit;
int ret;
@@ -338,20 +337,17 @@
* as we can't find a fitting bus via the qom tree, we have to add the
* event facility to the sysbus, so e.g. a sclp console can be created.
*/
- if (!sysbus_realize(SYS_BUS_DEVICE(sclp->event_facility), &err)) {
- goto out;
+ if (!sysbus_realize(SYS_BUS_DEVICE(sclp->event_facility), errp)) {
+ return;
}
ret = s390_set_memory_limit(machine->maxram_size, &hw_limit);
if (ret == -E2BIG) {
- error_setg(&err, "host supports a maximum of %" PRIu64 " GB",
+ error_setg(errp, "host supports a maximum of %" PRIu64 " GB",
hw_limit / GiB);
} else if (ret) {
- error_setg(&err, "setting the guest size failed");
+ error_setg(errp, "setting the guest size failed");
}
-
-out:
- error_propagate(errp, err);
}
static void sclp_memory_init(SCLPDevice *sclp)
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index ba27afe..b17bda3 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -723,15 +723,13 @@
static void usb_set_attached(Object *obj, bool value, Error **errp)
{
USBDevice *dev = USB_DEVICE(obj);
- Error *err = NULL;
if (dev->attached == value) {
return;
}
if (value) {
- usb_device_attach(dev, &err);
- error_propagate(errp, err);
+ usb_device_attach(dev, errp);
} else {
usb_device_detach(dev);
}