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/core/machine.c | |
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/core/machine.c')
-rw-r--r-- | hw/core/machine.c | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/hw/core/machine.c b/hw/core/machine.c index 0cd2033b1f..bb3a7b18b1 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -787,82 +787,78 @@ static void machine_class_init(ObjectClass *oc, void *data) mc->numa_auto_assign_ram = numa_default_auto_assign_ram; object_class_property_add_str(oc, "kernel", - machine_get_kernel, machine_set_kernel, &error_abort); + machine_get_kernel, machine_set_kernel); object_class_property_set_description(oc, "kernel", "Linux kernel image file"); object_class_property_add_str(oc, "initrd", - machine_get_initrd, machine_set_initrd, &error_abort); + machine_get_initrd, machine_set_initrd); object_class_property_set_description(oc, "initrd", "Linux initial ramdisk file"); object_class_property_add_str(oc, "append", - machine_get_append, machine_set_append, &error_abort); + machine_get_append, machine_set_append); object_class_property_set_description(oc, "append", "Linux kernel command line"); object_class_property_add_str(oc, "dtb", - machine_get_dtb, machine_set_dtb, &error_abort); + machine_get_dtb, machine_set_dtb); object_class_property_set_description(oc, "dtb", "Linux kernel device tree file"); object_class_property_add_str(oc, "dumpdtb", - machine_get_dumpdtb, machine_set_dumpdtb, &error_abort); + machine_get_dumpdtb, machine_set_dumpdtb); object_class_property_set_description(oc, "dumpdtb", "Dump current dtb to a file and quit"); object_class_property_add(oc, "phandle-start", "int", machine_get_phandle_start, machine_set_phandle_start, - NULL, NULL, &error_abort); + NULL, NULL); object_class_property_set_description(oc, "phandle-start", "The first phandle ID we may generate dynamically"); object_class_property_add_str(oc, "dt-compatible", - machine_get_dt_compatible, machine_set_dt_compatible, &error_abort); + machine_get_dt_compatible, machine_set_dt_compatible); object_class_property_set_description(oc, "dt-compatible", "Overrides the \"compatible\" property of the dt root node"); object_class_property_add_bool(oc, "dump-guest-core", - machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort); + machine_get_dump_guest_core, machine_set_dump_guest_core); object_class_property_set_description(oc, "dump-guest-core", "Include guest memory in a core dump"); object_class_property_add_bool(oc, "mem-merge", - machine_get_mem_merge, machine_set_mem_merge, &error_abort); + machine_get_mem_merge, machine_set_mem_merge); object_class_property_set_description(oc, "mem-merge", "Enable/disable memory merge support"); object_class_property_add_bool(oc, "usb", - machine_get_usb, machine_set_usb, &error_abort); + machine_get_usb, machine_set_usb); object_class_property_set_description(oc, "usb", "Set on/off to enable/disable usb"); object_class_property_add_bool(oc, "graphics", - machine_get_graphics, machine_set_graphics, &error_abort); + machine_get_graphics, machine_set_graphics); object_class_property_set_description(oc, "graphics", "Set on/off to enable/disable graphics emulation"); object_class_property_add_str(oc, "firmware", - machine_get_firmware, machine_set_firmware, - &error_abort); + machine_get_firmware, machine_set_firmware); object_class_property_set_description(oc, "firmware", "Firmware image"); object_class_property_add_bool(oc, "suppress-vmdesc", - machine_get_suppress_vmdesc, machine_set_suppress_vmdesc, - &error_abort); + machine_get_suppress_vmdesc, machine_set_suppress_vmdesc); object_class_property_set_description(oc, "suppress-vmdesc", "Set on to disable self-describing migration"); object_class_property_add_bool(oc, "enforce-config-section", - machine_get_enforce_config_section, machine_set_enforce_config_section, - &error_abort); + machine_get_enforce_config_section, machine_set_enforce_config_section); object_class_property_set_description(oc, "enforce-config-section", "Set on to enforce configuration section migration"); object_class_property_add_str(oc, "memory-encryption", - machine_get_memory_encryption, machine_set_memory_encryption, - &error_abort); + machine_get_memory_encryption, machine_set_memory_encryption); object_class_property_set_description(oc, "memory-encryption", "Set memory encryption object to use"); } @@ -893,16 +889,14 @@ static void machine_initfn(Object *obj) ms->nvdimms_state = g_new0(NVDIMMState, 1); object_property_add_bool(obj, "nvdimm", - machine_get_nvdimm, machine_set_nvdimm, - &error_abort); + machine_get_nvdimm, machine_set_nvdimm); object_property_set_description(obj, "nvdimm", "Set on/off to enable/disable " "NVDIMM instantiation"); object_property_add_str(obj, "nvdimm-persistence", machine_get_nvdimm_persistence, - machine_set_nvdimm_persistence, - &error_abort); + machine_set_nvdimm_persistence); object_property_set_description(obj, "nvdimm-persistence", "Set NVDIMM persistence" "Valid values are cpu, mem-ctrl"); @@ -911,8 +905,7 @@ static void machine_initfn(Object *obj) if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) { ms->numa_state = g_new0(NumaState, 1); object_property_add_bool(obj, "hmat", - machine_get_hmat, machine_set_hmat, - &error_abort); + machine_get_hmat, machine_set_hmat); object_property_set_description(obj, "hmat", "Set on/off to enable/disable " "ACPI Heterogeneous Memory Attribute " @@ -920,8 +913,7 @@ static void machine_initfn(Object *obj) } object_property_add_str(obj, "memory-backend", - machine_get_memdev, machine_set_memdev, - &error_abort); + machine_get_memdev, machine_set_memdev); object_property_set_description(obj, "memory-backend", "Set RAM backend" "Valid value is ID of hostmem based backend"); |