diff options
author | Markus Armbruster <armbru@redhat.com> | 2020-05-05 17:29:22 +0200 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2020-05-15 07:07:58 +0200 |
commit | d2623129a7dec1d3041ad1221dda1ca49c667532 (patch) | |
tree | 9bcac33dfaed2361cd536856159b9960135ccd46 /hw/ppc | |
parent | 9f742c28f52d55ff83dc441a0cea365239a4906d (diff) |
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
Diffstat (limited to 'hw/ppc')
-rw-r--r-- | hw/ppc/e500.c | 8 | ||||
-rw-r--r-- | hw/ppc/mac_newworld.c | 4 | ||||
-rw-r--r-- | hw/ppc/mac_oldworld.c | 2 | ||||
-rw-r--r-- | hw/ppc/pnv.c | 13 | ||||
-rw-r--r-- | hw/ppc/pnv_bmc.c | 5 | ||||
-rw-r--r-- | hw/ppc/pnv_core.c | 2 | ||||
-rw-r--r-- | hw/ppc/pnv_psi.c | 2 | ||||
-rw-r--r-- | hw/ppc/prep.c | 6 | ||||
-rw-r--r-- | hw/ppc/spapr.c | 25 | ||||
-rw-r--r-- | hw/ppc/spapr_caps.c | 8 | ||||
-rw-r--r-- | hw/ppc/spapr_cpu_core.c | 5 | ||||
-rw-r--r-- | hw/ppc/spapr_drc.c | 18 | ||||
-rw-r--r-- | hw/ppc/spapr_iommu.c | 2 | ||||
-rw-r--r-- | hw/ppc/spapr_irq.c | 2 | ||||
-rw-r--r-- | hw/ppc/spapr_rtc.c | 2 |
15 files changed, 39 insertions, 65 deletions
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c index 0d1f41197c..2a0b66a152 100644 --- a/hw/ppc/e500.c +++ b/hw/ppc/e500.c @@ -744,8 +744,7 @@ static DeviceState *ppce500_init_mpic_qemu(PPCE500MachineState *pms, const PPCE500MachineClass *pmc = PPCE500_MACHINE_GET_CLASS(pms); dev = qdev_create(NULL, TYPE_OPENPIC); - object_property_add_child(OBJECT(machine), "pic", OBJECT(dev), - &error_fatal); + object_property_add_child(OBJECT(machine), "pic", OBJECT(dev)); qdev_prop_set_uint32(dev, "model", pmc->mpic_version); qdev_prop_set_uint32(dev, "nb_cpus", smp_cpus); @@ -916,7 +915,7 @@ void ppce500_init(MachineState *machine) dev = qdev_create(NULL, "e500-ccsr"); object_property_add_child(qdev_get_machine(), "e500-ccsr", - OBJECT(dev), NULL); + OBJECT(dev)); qdev_init_nofail(dev); ccsr = CCSR(dev); ccsr_addr_space = &ccsr->ccsr_space; @@ -957,8 +956,7 @@ void ppce500_init(MachineState *machine) /* PCI */ dev = qdev_create(NULL, "e500-pcihost"); - object_property_add_child(qdev_get_machine(), "pci-host", OBJECT(dev), - &error_abort); + object_property_add_child(qdev_get_machine(), "pci-host", OBJECT(dev)); qdev_prop_set_uint32(dev, "first_slot", pmc->pci_first_slot); qdev_prop_set_uint32(dev, "first_pin_irq", pci_irq_nrs[0]); qdev_init_nofail(dev); diff --git a/hw/ppc/mac_newworld.c b/hw/ppc/mac_newworld.c index 55d1419442..3507f26f6e 100644 --- a/hw/ppc/mac_newworld.c +++ b/hw/ppc/mac_newworld.c @@ -455,7 +455,7 @@ static void ppc_core99_init(MachineState *machine) qdev_prop_set_uint32(dev, "data_width", 1); qdev_prop_set_bit(dev, "dma_enabled", false); object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, - OBJECT(fw_cfg), NULL); + OBJECT(fw_cfg)); qdev_init_nofail(dev); s = SYS_BUS_DEVICE(dev); sysbus_mmio_map(s, 0, CFG_ADDR); @@ -628,7 +628,7 @@ static void core99_instance_init(Object *obj) /* Default via_config is CORE99_VIA_CONFIG_CUDA */ cms->via_config = CORE99_VIA_CONFIG_CUDA; object_property_add_str(obj, "via", core99_get_via_config, - core99_set_via_config, NULL); + core99_set_via_config); object_property_set_description(obj, "via", "Set VIA configuration. " "Valid values are cuda, pmu and pmu-adb"); diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index 101bdc5c4d..0b4c1c6373 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -314,7 +314,7 @@ static void ppc_heathrow_init(MachineState *machine) qdev_prop_set_uint32(dev, "data_width", 1); qdev_prop_set_bit(dev, "dma_enabled", false); object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, - OBJECT(fw_cfg), NULL); + OBJECT(fw_cfg)); qdev_init_nofail(dev); s = SYS_BUS_DEVICE(dev); sysbus_mmio_map(s, 0, CFG_ADDR); diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 4666dbbe7a..da637822f9 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -832,7 +832,7 @@ static void pnv_init(MachineState *machine) } snprintf(chip_name, sizeof(chip_name), "chip[%d]", PNV_CHIP_HWID(i)); - object_property_add_child(OBJECT(pnv), chip_name, chip, &error_fatal); + object_property_add_child(OBJECT(pnv), chip_name, chip); object_property_set_int(chip, PNV_CHIP_HWID(i), "chip-id", &error_fatal); object_property_set_int(chip, machine->smp.cores, @@ -1060,8 +1060,7 @@ static void pnv_chip_power8_instance_init(Object *obj) object_property_add_link(obj, "xics", TYPE_XICS_FABRIC, (Object **)&chip8->xics, object_property_allow_set_link, - OBJ_PROP_LINK_STRONG, - &error_abort); + OBJ_PROP_LINK_STRONG); object_initialize_child(obj, "psi", &chip8->psi, sizeof(chip8->psi), TYPE_PNV8_PSI, &error_abort, NULL); @@ -1321,7 +1320,7 @@ static void pnv_chip_power9_instance_init(Object *obj) object_initialize_child(obj, "xive", &chip9->xive, sizeof(chip9->xive), TYPE_PNV_XIVE, &error_abort, NULL); object_property_add_alias(obj, "xive-fabric", OBJECT(&chip9->xive), - "xive-fabric", &error_abort); + "xive-fabric"); object_initialize_child(obj, "psi", &chip9->psi, sizeof(chip9->psi), TYPE_PNV9_PSI, &error_abort, NULL); @@ -1739,8 +1738,7 @@ static void pnv_chip_core_realize(PnvChip *chip, Error **errp) pnv_core = PNV_CORE(object_new(typename)); snprintf(core_name, sizeof(core_name), "core[%d]", core_hwid); - object_property_add_child(OBJECT(chip), core_name, OBJECT(pnv_core), - &error_abort); + object_property_add_child(OBJECT(chip), core_name, OBJECT(pnv_core)); chip->cores[i] = pnv_core; object_property_set_int(OBJECT(pnv_core), chip->nr_threads, "nr-threads", &error_fatal); @@ -2027,8 +2025,7 @@ static void pnv_machine_class_init(ObjectClass *oc, void *data) nc->nmi_monitor_handler = pnv_nmi; object_class_property_add_bool(oc, "hb-mode", - pnv_machine_get_hb, pnv_machine_set_hb, - &error_abort); + pnv_machine_get_hb, pnv_machine_set_hb); object_class_property_set_description(oc, "hb-mode", "Use a hostboot like boot loader"); } diff --git a/hw/ppc/pnv_bmc.c b/hw/ppc/pnv_bmc.c index 4e018b8b70..5f86453b6a 100644 --- a/hw/ppc/pnv_bmc.c +++ b/hw/ppc/pnv_bmc.c @@ -217,8 +217,7 @@ static const IPMINetfn hiomap_netfn = { void pnv_bmc_set_pnor(IPMIBmc *bmc, PnvPnor *pnor) { object_ref(OBJECT(pnor)); - object_property_add_const_link(OBJECT(bmc), "pnor", OBJECT(pnor), - &error_abort); + object_property_add_const_link(OBJECT(bmc), "pnor", OBJECT(pnor)); /* Install the HIOMAP protocol handlers to access the PNOR */ ipmi_sim_register_netfn(IPMI_BMC_SIMULATOR(bmc), IPMI_NETFN_OEM, @@ -235,7 +234,7 @@ IPMIBmc *pnv_bmc_create(PnvPnor *pnor) obj = object_new(TYPE_IPMI_BMC_SIMULATOR); object_ref(OBJECT(pnor)); - object_property_add_const_link(obj, "pnor", OBJECT(pnor), &error_abort); + object_property_add_const_link(obj, "pnor", OBJECT(pnor)); object_property_set_bool(obj, true, "realized", &error_fatal); /* Install the HIOMAP protocol handlers to access the PNOR */ diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index 234562040d..7033104676 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -232,7 +232,7 @@ static void pnv_core_realize(DeviceState *dev, Error **errp) pc->threads[i] = POWERPC_CPU(obj); snprintf(name, sizeof(name), "thread[%d]", i); - object_property_add_child(OBJECT(pc), name, obj, &error_abort); + object_property_add_child(OBJECT(pc), name, obj); cpu->machine_data = g_new0(PnvCPUState, 1); diff --git a/hw/ppc/pnv_psi.c b/hw/ppc/pnv_psi.c index c34a49b000..cfd5b7bc25 100644 --- a/hw/ppc/pnv_psi.c +++ b/hw/ppc/pnv_psi.c @@ -486,7 +486,7 @@ static void pnv_psi_power8_instance_init(Object *obj) object_initialize_child(obj, "ics-psi", &psi8->ics, sizeof(psi8->ics), TYPE_ICS, &error_abort, NULL); object_property_add_alias(obj, ICS_PROP_XICS, OBJECT(&psi8->ics), - ICS_PROP_XICS, &error_abort); + ICS_PROP_XICS); } static const uint8_t irq_to_xivr[] = { diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index 44be9d25a2..9266453dd9 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -229,7 +229,7 @@ static int prep_set_cmos_checksum(DeviceState *dev, void *opaque) rtc_set_memory(rtc, 0x3f, checksum >> 8); object_property_add_alias(qdev_get_machine(), "rtc-time", OBJECT(rtc), - "date", NULL); + "date"); } return 0; } @@ -275,7 +275,7 @@ static void ibm_40p_init(MachineState *machine) qdev_prop_set_string(dev, "bios-name", bios_name); qdev_prop_set_uint32(dev, "elf-machine", PPC_ELF_MACHINE); pcihost = SYS_BUS_DEVICE(dev); - object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL); + object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev)); qdev_init_nofail(dev); pci_bus = PCI_BUS(qdev_get_child_bus(dev, "pci.0")); if (!pci_bus) { @@ -343,7 +343,7 @@ static void ibm_40p_init(MachineState *machine) qdev_prop_set_uint32(dev, "data_width", 1); qdev_prop_set_bit(dev, "dma_enabled", false); object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG, - OBJECT(fw_cfg), NULL); + OBJECT(fw_cfg)); qdev_init_nofail(dev); s = SYS_BUS_DEVICE(dev); sysbus_mmio_map(s, 0, CFG_ADDR); diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index aa281e727a..976d40f60f 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1732,7 +1732,7 @@ static void spapr_rtc_create(SpaprMachineState *spapr) object_property_set_bool(OBJECT(&spapr->rtc), true, "realized", &error_fatal); object_property_add_alias(OBJECT(spapr), "rtc-time", OBJECT(&spapr->rtc), - "date", &error_fatal); + "date"); } /* Returns whether we want to use VGA or not */ @@ -3305,13 +3305,12 @@ static void spapr_instance_init(Object *obj) spapr->htab_fd = -1; spapr->use_hotplug_event_source = true; object_property_add_str(obj, "kvm-type", - spapr_get_kvm_type, spapr_set_kvm_type, NULL); + spapr_get_kvm_type, spapr_set_kvm_type); object_property_set_description(obj, "kvm-type", "Specifies the KVM virtualization mode (HV, PR)"); object_property_add_bool(obj, "modern-hotplug-events", spapr_get_modern_hotplug_events, - spapr_set_modern_hotplug_events, - NULL); + spapr_set_modern_hotplug_events); object_property_set_description(obj, "modern-hotplug-events", "Use dedicated hotplug event mechanism in" " place of standard EPOW events when possible" @@ -3321,22 +3320,20 @@ static void spapr_instance_init(Object *obj) &error_fatal); object_property_add_str(obj, "resize-hpt", - spapr_get_resize_hpt, spapr_set_resize_hpt, NULL); + spapr_get_resize_hpt, spapr_set_resize_hpt); object_property_set_description(obj, "resize-hpt", "Resizing of the Hash Page Table (enabled, disabled, required)"); object_property_add_uint32_ptr(obj, "vsmt", - &spapr->vsmt, OBJ_PROP_FLAG_READWRITE, - &error_abort); + &spapr->vsmt, OBJ_PROP_FLAG_READWRITE); object_property_set_description(obj, "vsmt", "Virtual SMT: KVM behaves as if this were" " the host's SMT mode"); object_property_add_bool(obj, "vfio-no-msix-emulation", - spapr_get_msix_emulation, NULL, NULL); + spapr_get_msix_emulation, NULL); object_property_add_uint64_ptr(obj, "kernel-addr", - &spapr->kernel_addr, OBJ_PROP_FLAG_READWRITE, - &error_abort); + &spapr->kernel_addr, OBJ_PROP_FLAG_READWRITE); object_property_set_description(obj, "kernel-addr", stringify(KERNEL_LOAD_ADDR) " for -kernel is the default"); @@ -3344,18 +3341,16 @@ static void spapr_instance_init(Object *obj) /* The machine class defines the default interrupt controller mode */ spapr->irq = smc->irq; object_property_add_str(obj, "ic-mode", spapr_get_ic_mode, - spapr_set_ic_mode, NULL); + spapr_set_ic_mode); object_property_set_description(obj, "ic-mode", "Specifies the interrupt controller mode (xics, xive, dual)"); object_property_add_str(obj, "host-model", - spapr_get_host_model, spapr_set_host_model, - &error_abort); + spapr_get_host_model, spapr_set_host_model); object_property_set_description(obj, "host-model", "Host model to advertise in guest device tree"); object_property_add_str(obj, "host-serial", - spapr_get_host_serial, spapr_set_host_serial, - &error_abort); + spapr_get_host_serial, spapr_set_host_serial); object_property_set_description(obj, "host-serial", "Host serial number to advertise in guest device tree"); } diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 0870961fc9..184563e608 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -826,7 +826,6 @@ void spapr_caps_cpu_apply(SpaprMachineState *spapr, PowerPCCPU *cpu) void spapr_caps_add_properties(SpaprMachineClass *smc, Error **errp) { - Error *local_err = NULL; ObjectClass *klass = OBJECT_CLASS(smc); int i; @@ -837,12 +836,7 @@ void spapr_caps_add_properties(SpaprMachineClass *smc, Error **errp) object_class_property_add(klass, name, cap->type, cap->get, cap->set, - NULL, cap, &local_err); - if (local_err) { - error_propagate(errp, local_err); - g_free(name); - return; - } + NULL, cap); desc = g_strdup_printf("%s", cap->description); object_class_property_set_description(klass, name, desc); diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index ac1c109427..df5c7742ca 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -290,11 +290,8 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) cpu->node_id = sc->node_id; id = g_strdup_printf("thread[%d]", i); - object_property_add_child(OBJECT(sc), id, obj, &local_err); + object_property_add_child(OBJECT(sc), id, obj); g_free(id); - if (local_err) { - goto err; - } cpu->machine_data = g_new0(SpaprCpuState, 1); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 0b66d59867..728307a992 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -392,7 +392,7 @@ void spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp) object_property_add_link(OBJECT(drc), "device", object_get_typename(OBJECT(drc->dev)), (Object **)(&drc->dev), - NULL, 0, NULL); + NULL, 0); } static void spapr_drc_release(SpaprDrc *drc) @@ -519,7 +519,6 @@ static void realize(DeviceState *d, Error **errp) Object *root_container; gchar *link_name; char *child_name; - Error *err = NULL; trace_spapr_drc_realize(spapr_drc_index(drc)); /* NOTE: we do this as part of realize/unrealize due to the fact @@ -534,13 +533,9 @@ static void realize(DeviceState *d, Error **errp) child_name = object_get_canonical_path_component(OBJECT(drc)); trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name); object_property_add_alias(root_container, link_name, - drc->owner, child_name, &err); + drc->owner, child_name); g_free(child_name); g_free(link_name); - if (err) { - error_propagate(errp, err); - return; - } vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr_drc, drc); trace_spapr_drc_realize_complete(spapr_drc_index(drc)); @@ -570,7 +565,7 @@ SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type, drc->owner = owner; prop_name = g_strdup_printf("dr-connector[%"PRIu32"]", spapr_drc_index(drc)); - object_property_add_child(owner, prop_name, OBJECT(drc), &error_abort); + object_property_add_child(owner, prop_name, OBJECT(drc)); object_unref(OBJECT(drc)); object_property_set_bool(OBJECT(drc), true, "realized", NULL); g_free(prop_name); @@ -583,12 +578,11 @@ static void spapr_dr_connector_instance_init(Object *obj) SpaprDrc *drc = SPAPR_DR_CONNECTOR(obj); SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); - object_property_add_uint32_ptr(obj, "id", &drc->id, OBJ_PROP_FLAG_READ, - NULL); + object_property_add_uint32_ptr(obj, "id", &drc->id, OBJ_PROP_FLAG_READ); object_property_add(obj, "index", "uint32", prop_get_index, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL); object_property_add(obj, "fdt", "struct", prop_get_fdt, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL); drc->state = drck->empty_state; } diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index 5704fe6051..601b896214 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -365,7 +365,7 @@ SpaprTceTable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn) tcet->liobn = liobn; tmp = g_strdup_printf("tce-table-%x", liobn); - object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL); + object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet)); g_free(tmp); object_unref(OBJECT(tcet)); diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index 1f630f296b..0c594aa72e 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -307,7 +307,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp) obj = object_new(TYPE_ICS_SPAPR); - object_property_add_child(OBJECT(spapr), "ics", obj, &error_abort); + object_property_add_child(OBJECT(spapr), "ics", obj); object_property_set_link(obj, OBJECT(spapr), ICS_PROP_XICS, &error_abort); object_property_set_int(obj, smc->nr_xirqs, "nr-irqs", &error_abort); diff --git a/hw/ppc/spapr_rtc.c b/hw/ppc/spapr_rtc.c index 42ff72c269..68cfc578a3 100644 --- a/hw/ppc/spapr_rtc.c +++ b/hw/ppc/spapr_rtc.c @@ -149,7 +149,7 @@ static void spapr_rtc_realize(DeviceState *dev, Error **errp) rtc_ns = qemu_clock_get_ns(rtc_clock); rtc->ns_offset = host_s * NANOSECONDS_PER_SECOND - rtc_ns; - object_property_add_tm(OBJECT(rtc), "date", spapr_rtc_qom_date, NULL); + object_property_add_tm(OBJECT(rtc), "date", spapr_rtc_qom_date); } static const VMStateDescription vmstate_spapr_rtc = { |