Skip to content

Commit

Permalink
error: Eliminate error_propagate() manually
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
Markus Armbruster committed Jul 10, 2020
1 parent af175e8 commit 992861f
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 149 deletions.
4 changes: 1 addition & 3 deletions block/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ static void reopen_backing_file(BlockDriverState *bs, bool writable,
{
BDRVReplicationState *s = bs->opaque;
BlockReopenQueue *reopen_queue = NULL;
Error *local_err = NULL;

if (writable) {
s->orig_hidden_read_only = bdrv_is_read_only(s->hidden_disk->bs);
Expand All @@ -392,8 +391,7 @@ static void reopen_backing_file(BlockDriverState *bs, bool writable,
}

if (reopen_queue) {
bdrv_reopen_multiple(reopen_queue, &local_err);
error_propagate(errp, local_err);
bdrv_reopen_multiple(reopen_queue, errp);
}

bdrv_subtree_drained_end(s->hidden_disk->bs);
Expand Down
16 changes: 4 additions & 12 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type,
bool read_only = false;
bool copy_on_read;
const char *filename;
Error *local_err = NULL;
int i;

/* Change legacy command line options into QMP ones */
Expand Down Expand Up @@ -1003,13 +1002,10 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type,
}

/* Actual block device init: Functionality shared with blockdev-add */
blk = blockdev_init(filename, bs_opts, &local_err);
blk = blockdev_init(filename, bs_opts, errp);
bs_opts = NULL;
if (!blk) {
error_propagate(errp, local_err);
goto fail;
} else {
assert(!local_err);
}

/* Create legacy DriveInfo */
Expand Down Expand Up @@ -3141,9 +3137,8 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp)
arg->has_copy_mode, arg->copy_mode,
arg->has_auto_finalize, arg->auto_finalize,
arg->has_auto_dismiss, arg->auto_dismiss,
&local_err);
errp);
bdrv_unref(target_bs);
error_propagate(errp, local_err);
out:
aio_context_release(aio_context);
}
Expand Down Expand Up @@ -3171,7 +3166,6 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
AioContext *aio_context;
AioContext *old_context;
BlockMirrorBackingMode backing_mode = MIRROR_LEAVE_BACKING_CHAIN;
Error *local_err = NULL;
bool zero_target;
int ret;

Expand Down Expand Up @@ -3213,8 +3207,7 @@ void qmp_blockdev_mirror(bool has_job_id, const char *job_id,
has_copy_mode, copy_mode,
has_auto_finalize, auto_finalize,
has_auto_dismiss, auto_dismiss,
&local_err);
error_propagate(errp, local_err);
errp);
out:
aio_context_release(aio_context);
}
Expand Down Expand Up @@ -3433,8 +3426,7 @@ void qmp_change_backing_file(const char *device,
}

if (ro) {
bdrv_reopen_set_read_only(image_bs, true, &local_err);
error_propagate(errp, local_err);
bdrv_reopen_set_read_only(image_bs, true, errp);
}

out:
Expand Down
6 changes: 2 additions & 4 deletions bootdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,13 @@ static void device_set_bootindex(Object *obj, Visitor *v, const char *name,
/* check whether bootindex is present in fw_boot_order list */
check_boot_index(boot_index, &local_err);
if (local_err) {
goto out;
error_propagate(errp, local_err);
return;
}
/* change bootindex to a new one */
*prop->bootindex = boot_index;

add_boot_device_path(*prop->bootindex, prop->dev, prop->suffix);

out:
error_propagate(errp, local_err);
}

static void property_release_bootindex(Object *obj, const char *name,
Expand Down
7 changes: 2 additions & 5 deletions dump/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,14 +1031,11 @@ static void create_header64(DumpState *s, Error **errp)

static void write_dump_header(DumpState *s, Error **errp)
{
Error *local_err = NULL;

if (s->dump_info.d_class == ELFCLASS32) {
create_header32(s, &local_err);
create_header32(s, errp);
} else {
create_header64(s, &local_err);
create_header64(s, errp);
}
error_propagate(errp, local_err);
}

static size_t dump_bitmap_get_bufsize(DumpState *s)
Expand Down
8 changes: 3 additions & 5 deletions hw/block/fdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}

Expand Down
44 changes: 14 additions & 30 deletions hw/core/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions hw/i386/x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions hw/intc/xive.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,24 +757,18 @@ 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);
object_property_add_child(cpu, TYPE_XIVE_TCTX, obj);
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)
Expand Down
14 changes: 4 additions & 10 deletions hw/ppc/spapr_cpu_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions hw/s390x/s390-pci-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions hw/s390x/s390-virtio-ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 4 additions & 8 deletions hw/s390x/sclp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions hw/usb/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 992861f

Please sign in to comment.