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/misc | |
parent | 9f742c28f52d55ff83dc441a0cea365239a4906d (diff) | |
download | qemu-d2623129a7dec1d3041ad1221dda1ca49c667532.zip qemu-d2623129a7dec1d3041ad1221dda1ca49c667532.tar.gz qemu-d2623129a7dec1d3041ad1221dda1ca49c667532.tar.bz2 |
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/misc')
-rw-r--r-- | hw/misc/aspeed_sdmc.c | 2 | ||||
-rw-r--r-- | hw/misc/edu.c | 3 | ||||
-rw-r--r-- | hw/misc/mac_via.c | 4 | ||||
-rw-r--r-- | hw/misc/macio/gpio.c | 2 | ||||
-rw-r--r-- | hw/misc/macio/macio.c | 4 | ||||
-rw-r--r-- | hw/misc/macio/pmu.c | 2 | ||||
-rw-r--r-- | hw/misc/pca9552.c | 2 | ||||
-rw-r--r-- | hw/misc/tmp105.c | 2 | ||||
-rw-r--r-- | hw/misc/tmp421.c | 8 |
9 files changed, 14 insertions, 15 deletions
diff --git a/hw/misc/aspeed_sdmc.c b/hw/misc/aspeed_sdmc.c index 14db9cf..25e1e58 100644 --- a/hw/misc/aspeed_sdmc.c +++ b/hw/misc/aspeed_sdmc.c @@ -250,7 +250,7 @@ static void aspeed_sdmc_initfn(Object *obj) { object_property_add(obj, "ram-size", "int", aspeed_sdmc_get_ram_size, aspeed_sdmc_set_ram_size, - NULL, NULL, NULL); + NULL, NULL); } static void aspeed_sdmc_realize(DeviceState *dev, Error **errp) diff --git a/hw/misc/edu.c b/hw/misc/edu.c index ff10f5b..ec617e6 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -402,8 +402,7 @@ static void edu_instance_init(Object *obj) edu->dma_mask = (1UL << 28) - 1; object_property_add_uint64_ptr(obj, "dma_mask", - &edu->dma_mask, OBJ_PROP_FLAG_READWRITE, - NULL); + &edu->dma_mask, OBJ_PROP_FLAG_READWRITE); } static void edu_class_init(ObjectClass *class, void *data) diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c index 8134330..e05623d 100644 --- a/hw/misc/mac_via.c +++ b/hw/misc/mac_via.c @@ -885,10 +885,10 @@ static void mac_via_realize(DeviceState *dev, Error **errp) /* Pass through mos6522 output IRQs */ ms = MOS6522(&m->mos6522_via1); object_property_add_alias(OBJECT(dev), "irq[0]", OBJECT(ms), - SYSBUS_DEVICE_GPIO_IRQ "[0]", &error_abort); + SYSBUS_DEVICE_GPIO_IRQ "[0]"); ms = MOS6522(&m->mos6522_via2); object_property_add_alias(OBJECT(dev), "irq[1]", OBJECT(ms), - SYSBUS_DEVICE_GPIO_IRQ "[0]", &error_abort); + SYSBUS_DEVICE_GPIO_IRQ "[0]"); /* Pass through mos6522 input IRQs */ qdev_pass_gpios(DEVICE(&m->mos6522_via1), dev, "via1-irq"); diff --git a/hw/misc/macio/gpio.c b/hw/misc/macio/gpio.c index 6cca6b2..0fef8fb 100644 --- a/hw/misc/macio/gpio.c +++ b/hw/misc/macio/gpio.c @@ -170,7 +170,7 @@ static void macio_gpio_init(Object *obj) object_property_add_link(obj, "pic", TYPE_OPENPIC, (Object **) &s->pic, qdev_prop_allow_set_link_before_realize, - 0, NULL); + 0); memory_region_init_io(&s->gpiomem, OBJECT(s), &macio_gpio_ops, obj, "gpio", 0x30); diff --git a/hw/misc/macio/macio.c b/hw/misc/macio/macio.c index 7922219..3779865 100644 --- a/hw/misc/macio/macio.c +++ b/hw/misc/macio/macio.c @@ -241,7 +241,7 @@ static void macio_oldworld_init(Object *obj) object_property_add_link(obj, "pic", TYPE_HEATHROW, (Object **) &os->pic, qdev_prop_allow_set_link_before_realize, - 0, NULL); + 0); macio_init_child_obj(s, "cuda", &s->cuda, sizeof(s->cuda), TYPE_CUDA); @@ -397,7 +397,7 @@ static void macio_newworld_init(Object *obj) object_property_add_link(obj, "pic", TYPE_OPENPIC, (Object **) &ns->pic, qdev_prop_allow_set_link_before_realize, - 0, NULL); + 0); macio_init_child_obj(s, "gpio", &ns->gpio, sizeof(ns->gpio), TYPE_MACIO_GPIO); diff --git a/hw/misc/macio/pmu.c b/hw/misc/macio/pmu.c index b8466a4..5fa7928 100644 --- a/hw/misc/macio/pmu.c +++ b/hw/misc/macio/pmu.c @@ -773,7 +773,7 @@ static void pmu_init(Object *obj) object_property_add_link(obj, "gpio", TYPE_MACIO_GPIO, (Object **) &s->gpio, qdev_prop_allow_set_link_before_realize, - 0, NULL); + 0); sysbus_init_child_obj(obj, "mos6522-pmu", &s->mos6522_pmu, sizeof(s->mos6522_pmu), TYPE_MOS6522_PMU); diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index efd961e..cac729e 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -298,7 +298,7 @@ static void pca9552_initfn(Object *obj) name = g_strdup_printf("led%d", led); object_property_add(obj, name, "bool", pca9552_get_led, pca9552_set_led, - NULL, NULL, NULL); + NULL, NULL); g_free(name); } } diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index 75ddad3..58dbebc 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -245,7 +245,7 @@ static void tmp105_initfn(Object *obj) { object_property_add(obj, "temperature", "int", tmp105_get_temperature, - tmp105_set_temperature, NULL, NULL, NULL); + tmp105_set_temperature, NULL, NULL); } static void tmp105_class_init(ObjectClass *klass, void *data) diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c index c0bc150..74864cd 100644 --- a/hw/misc/tmp421.c +++ b/hw/misc/tmp421.c @@ -347,16 +347,16 @@ static void tmp421_initfn(Object *obj) { object_property_add(obj, "temperature0", "int", tmp421_get_temperature, - tmp421_set_temperature, NULL, NULL, NULL); + tmp421_set_temperature, NULL, NULL); object_property_add(obj, "temperature1", "int", tmp421_get_temperature, - tmp421_set_temperature, NULL, NULL, NULL); + tmp421_set_temperature, NULL, NULL); object_property_add(obj, "temperature2", "int", tmp421_get_temperature, - tmp421_set_temperature, NULL, NULL, NULL); + tmp421_set_temperature, NULL, NULL); object_property_add(obj, "temperature3", "int", tmp421_get_temperature, - tmp421_set_temperature, NULL, NULL, NULL); + tmp421_set_temperature, NULL, NULL); } static void tmp421_class_init(ObjectClass *klass, void *data) |