summaryrefslogtreecommitdiffstats
path: root/hw/core
diff options
context:
space:
mode:
authorMarkus Armbruster2020-05-05 17:29:22 +0200
committerMarkus Armbruster2020-05-15 07:07:58 +0200
commitd2623129a7dec1d3041ad1221dda1ca49c667532 (patch)
tree9bcac33dfaed2361cd536856159b9960135ccd46 /hw/core
parentqdev: Clean up qdev_connect_gpio_out_named() (diff)
downloadqemu-d2623129a7dec1d3041ad1221dda1ca49c667532.tar.gz
qemu-d2623129a7dec1d3041ad1221dda1ca49c667532.tar.xz
qemu-d2623129a7dec1d3041ad1221dda1ca49c667532.zip
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')
-rw-r--r--hw/core/bus.c7
-rw-r--r--hw/core/machine.c46
-rw-r--r--hw/core/qdev-clock.c4
-rw-r--r--hw/core/qdev-properties.c9
-rw-r--r--hw/core/qdev.c40
5 files changed, 41 insertions, 65 deletions
diff --git a/hw/core/bus.c b/hw/core/bus.c
index 3dc0a825f0..4a57ae107e 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -122,7 +122,7 @@ static void qbus_realize(BusState *bus, DeviceState *parent, const char *name)
if (bus->parent) {
QLIST_INSERT_HEAD(&bus->parent->child_bus, bus, sibling);
bus->parent->num_child_bus++;
- object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus), NULL);
+ object_property_add_child(OBJECT(bus->parent), bus->name, OBJECT(bus));
object_unref(OBJECT(bus));
} else {
/* The only bus without a parent is the main system bus */
@@ -215,10 +215,9 @@ static void qbus_initfn(Object *obj)
TYPE_HOTPLUG_HANDLER,
(Object **)&bus->hotplug_handler,
object_property_allow_set_link,
- 0,
- NULL);
+ 0);
object_property_add_bool(obj, "realized",
- bus_get_realized, bus_set_realized, NULL);
+ bus_get_realized, bus_set_realized);
}
static char *default_bus_get_fw_dev_path(DeviceState *dev)
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");
diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c
index a94cc44437..5cc1e82e51 100644
--- a/hw/core/qdev-clock.c
+++ b/hw/core/qdev-clock.c
@@ -46,7 +46,7 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name,
*/
if (clk == NULL) {
clk = CLOCK(object_new(TYPE_CLOCK));
- object_property_add_child(OBJECT(dev), name, OBJECT(clk), &error_abort);
+ object_property_add_child(OBJECT(dev), name, OBJECT(clk));
if (output) {
/*
* Remove object_new()'s initial reference.
@@ -59,7 +59,7 @@ static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name,
object_property_add_link(OBJECT(dev), name,
object_get_typename(OBJECT(clk)),
(Object **) &ncl->clock,
- NULL, OBJ_PROP_LINK_STRONG, &error_abort);
+ NULL, OBJ_PROP_LINK_STRONG);
}
ncl->clock = clk;
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 2047114fca..2f294ec4a4 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1043,11 +1043,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
arrayprop->prop.info->get,
arrayprop->prop.info->set,
array_element_release,
- arrayprop, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
+ arrayprop);
}
}
@@ -1259,8 +1255,7 @@ static void create_link_property(ObjectClass *oc, Property *prop, Error **errp)
object_class_property_add_link(oc, prop->name, prop->link_type,
prop->offset,
qdev_prop_allow_set_link_before_realize,
- OBJ_PROP_LINK_STRONG,
- errp);
+ OBJ_PROP_LINK_STRONG);
}
const PropertyInfo qdev_prop_link = {
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 2e6c29ba78..3f91bff712 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -91,8 +91,7 @@ static void bus_add_child(BusState *bus, DeviceState *child)
object_get_typename(OBJECT(child)),
(Object **)&kid->child,
NULL, /* read-only property */
- 0, /* return ownership on prop deletion */
- NULL);
+ 0);
}
void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
@@ -481,7 +480,7 @@ void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
gchar *propname = g_strdup_printf("%s[%u]", name, i);
object_property_add_child(OBJECT(dev), propname,
- OBJECT(gpio_list->in[i]), &error_abort);
+ OBJECT(gpio_list->in[i]));
g_free(propname);
}
@@ -512,8 +511,7 @@ void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
object_property_add_link(OBJECT(dev), propname, TYPE_IRQ,
(Object **)&pins[i],
object_property_allow_set_link,
- OBJ_PROP_LINK_STRONG,
- &error_abort);
+ OBJ_PROP_LINK_STRONG);
g_free(propname);
}
gpio_list->num_out += n;
@@ -546,8 +544,7 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
/* We need a name for object_property_set_link to work */
object_property_add_child(container_get(qdev_get_machine(),
"/unattached"),
- "non-qdev-gpio[*]", OBJECT(pin),
- &error_abort);
+ "non-qdev-gpio[*]", OBJECT(pin));
}
object_property_set_link(OBJECT(dev), OBJECT(pin), propname, &error_abort);
g_free(propname);
@@ -605,8 +602,7 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
char *propname = g_strdup_printf("%s[%d]", nm, i);
object_property_add_alias(OBJECT(container), propname,
- OBJECT(dev), propname,
- &error_abort);
+ OBJECT(dev), propname);
g_free(propname);
}
for (i = 0; i < ngl->num_out; i++) {
@@ -614,8 +610,7 @@ void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
char *propname = g_strdup_printf("%s[%d]", nm, i);
object_property_add_alias(OBJECT(container), propname,
- OBJECT(dev), propname,
- &error_abort);
+ OBJECT(dev), propname);
g_free(propname);
}
QLIST_REMOVE(ngl, node);
@@ -756,7 +751,7 @@ static void qdev_class_add_legacy_property(DeviceClass *dc, Property *prop)
name = g_strdup_printf("legacy-%s", prop->name);
object_class_property_add(OBJECT_CLASS(dc), name, "str",
prop->info->print ? qdev_get_legacy_property : prop->info->get,
- NULL, NULL, prop, &error_abort);
+ NULL, NULL, prop);
}
void qdev_property_add_static(DeviceState *dev, Property *prop)
@@ -769,7 +764,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop)
op = object_property_add(obj, prop->name, prop->info->name,
prop->info->get, prop->info->set,
prop->info->release,
- prop, &error_abort);
+ prop);
object_property_set_description(obj, prop->name,
prop->info->description);
@@ -795,7 +790,7 @@ static void qdev_class_add_property(DeviceClass *klass, Property *prop)
prop->name, prop->info->name,
prop->info->get, prop->info->set,
prop->info->release,
- prop, &error_abort);
+ prop);
if (prop->set_default) {
prop->info->set_default_value(op, prop);
}
@@ -818,8 +813,7 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
for (prop = dc->props_; prop && prop->name; prop++) {
object_property_add_alias(source, prop->name,
- OBJECT(target), prop->name,
- &error_abort);
+ OBJECT(target), prop->name);
}
class = object_class_get_parent(class);
} while (class != object_class_by_name(TYPE_DEVICE));
@@ -871,7 +865,7 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
object_property_add_child(container_get(qdev_get_machine(),
"/unattached"),
- name, obj, &error_abort);
+ name, obj);
unattached_parent = true;
g_free(name);
}
@@ -1198,17 +1192,13 @@ static void device_class_init(ObjectClass *class, void *data)
rc->get_transitional_function = device_get_transitional_reset;
object_class_property_add_bool(class, "realized",
- device_get_realized, device_set_realized,
- &error_abort);
+ device_get_realized, device_set_realized);
object_class_property_add_bool(class, "hotpluggable",
- device_get_hotpluggable, NULL,
- &error_abort);
+ device_get_hotpluggable, NULL);
object_class_property_add_bool(class, "hotplugged",
- device_get_hotplugged, NULL,
- &error_abort);
+ device_get_hotplugged, NULL);
object_class_property_add_link(class, "parent_bus", TYPE_BUS,
- offsetof(DeviceState, parent_bus), NULL, 0,
- &error_abort);
+ offsetof(DeviceState, parent_bus), NULL, 0);
}
void device_class_set_props(DeviceClass *dc, Property *props)