aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2020-07-07 18:06:04 +0200
committerMarkus Armbruster <armbru@redhat.com>2020-07-10 15:18:08 +0200
commit992861fb1e4cf410f30ec8f05bd2dc2a14a5a027 (patch)
tree9d4d5de47d4ebae50838cd7f8ea39b89a3604507 /hw
parentaf175e85f92c870386ad74f466e29537b79611d3 (diff)
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>
Diffstat (limited to 'hw')
-rw-r--r--hw/block/fdc.c8
-rw-r--r--hw/core/numa.c44
-rw-r--r--hw/i386/x86.c6
-rw-r--r--hw/intc/xive.c12
-rw-r--r--hw/ppc/spapr_cpu_core.c14
-rw-r--r--hw/s390x/s390-pci-bus.c4
-rw-r--r--hw/s390x/s390-virtio-ccw.c6
-rw-r--r--hw/s390x/sclp.c12
-rw-r--r--hw/usb/bus.c4
9 files changed, 34 insertions, 76 deletions
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index f22f46c9c9..e9ed3eef45 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -2528,7 +2528,7 @@ static void fdctrl_connect_drives(FDCtrl *fdctrl, DeviceState *fdc_dev,
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 @@ static void fdctrl_connect_drives(FDCtrl *fdctrl, DeviceState *fdc_dev,
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 de9a2f7e32..1b3267a607 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -456,40 +456,33 @@ void parse_numa_hmat_cache(MachineState *ms, NumaHmatCacheOptions *node,
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 @@ void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
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 @@ void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
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 22b524e0ab..67bee1bcb8 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -118,17 +118,15 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
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 34591659d3..9a162431e0 100644
--- a/hw/intc/xive.c
+++ b/hw/intc/xive.c
@@ -757,7 +757,6 @@ static const TypeInfo xive_tctx_info = {
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 *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp)
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 85330d08a1..c4f47dcc04 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -239,8 +239,8 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
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 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
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 24de4edfc6..92146a2119 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -743,7 +743,6 @@ static void s390_pcihost_realize(DeviceState *dev, Error **errp)
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 @@ static void s390_pcihost_realize(DeviceState *dev, Error **errp)
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 20e8e95c61..8cc2f25d8a 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -68,20 +68,18 @@ static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
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 03364343eb..a0ce444b4b 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -329,7 +329,6 @@ static void sclp_realize(DeviceState *dev, Error **errp)
{
MachineState *machine = MACHINE(qdev_get_machine());
SCLPDevice *sclp = SCLP(dev);
- Error *err = NULL;
uint64_t hw_limit;
int ret;
@@ -338,20 +337,17 @@ static void sclp_realize(DeviceState *dev, Error **errp)
* 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 ba27afe9f2..b17bda3b29 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -723,15 +723,13 @@ static bool usb_get_attached(Object *obj, Error **errp)
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);
}