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 /net | |
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 'net')
-rw-r--r-- | net/can/can_host.c | 3 | ||||
-rw-r--r-- | net/can/can_socketcan.c | 3 | ||||
-rw-r--r-- | net/colo-compare.c | 20 | ||||
-rw-r--r-- | net/dump.c | 4 | ||||
-rw-r--r-- | net/filter-buffer.c | 2 | ||||
-rw-r--r-- | net/filter-mirror.c | 10 | ||||
-rw-r--r-- | net/filter-rewriter.c | 2 | ||||
-rw-r--r-- | net/filter.c | 15 |
8 files changed, 24 insertions, 35 deletions
diff --git a/net/can/can_host.c b/net/can/can_host.c index 1dfaf0c..be4547d 100644 --- a/net/can/can_host.c +++ b/net/can/can_host.c @@ -79,8 +79,7 @@ static void can_host_instance_init(Object *obj) object_property_add_link(obj, "canbus", TYPE_CAN_BUS, (Object **)&ch->bus, object_property_allow_set_link, - OBJ_PROP_LINK_STRONG, - &error_abort); + OBJ_PROP_LINK_STRONG); } static void can_host_class_init(ObjectClass *klass, diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c index 807f31f..b7ef63e 100644 --- a/net/can/can_socketcan.c +++ b/net/can/can_socketcan.c @@ -266,8 +266,7 @@ static void can_host_socketcan_class_init(ObjectClass *klass, object_class_property_add_str(klass, "if", can_host_socketcan_get_if, - can_host_socketcan_set_if, - &error_abort); + can_host_socketcan_set_if); chc->connect = can_host_socketcan_connect; chc->disconnect = can_host_socketcan_disconnect; } diff --git a/net/colo-compare.c b/net/colo-compare.c index 10c0239..c07e7c1 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -1245,34 +1245,30 @@ static void colo_compare_init(Object *obj) CompareState *s = COLO_COMPARE(obj); object_property_add_str(obj, "primary_in", - compare_get_pri_indev, compare_set_pri_indev, - NULL); + compare_get_pri_indev, compare_set_pri_indev); object_property_add_str(obj, "secondary_in", - compare_get_sec_indev, compare_set_sec_indev, - NULL); + compare_get_sec_indev, compare_set_sec_indev); object_property_add_str(obj, "outdev", - compare_get_outdev, compare_set_outdev, - NULL); + compare_get_outdev, compare_set_outdev); object_property_add_link(obj, "iothread", TYPE_IOTHREAD, (Object **)&s->iothread, object_property_allow_set_link, - OBJ_PROP_LINK_STRONG, NULL); + OBJ_PROP_LINK_STRONG); /* This parameter just for Xen COLO */ object_property_add_str(obj, "notify_dev", - compare_get_notify_dev, compare_set_notify_dev, - NULL); + compare_get_notify_dev, compare_set_notify_dev); object_property_add(obj, "compare_timeout", "uint32", compare_get_timeout, - compare_set_timeout, NULL, NULL, NULL); + compare_set_timeout, NULL, NULL); object_property_add(obj, "expired_scan_cycle", "uint32", compare_get_expired_scan_cycle, - compare_set_expired_scan_cycle, NULL, NULL, NULL); + compare_set_expired_scan_cycle, NULL, NULL); s->vnet_hdr = false; object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr, - compare_set_vnet_hdr, NULL); + compare_set_vnet_hdr); } static void colo_compare_finalize(Object *obj) @@ -232,9 +232,9 @@ static void filter_dump_instance_init(Object *obj) nfds->maxlen = 65536; object_property_add(obj, "maxlen", "uint32", filter_dump_get_maxlen, - filter_dump_set_maxlen, NULL, NULL, NULL); + filter_dump_set_maxlen, NULL, NULL); object_property_add_str(obj, "file", file_dump_get_filename, - file_dump_set_filename, NULL); + file_dump_set_filename); } static void filter_dump_instance_finalize(Object *obj) diff --git a/net/filter-buffer.c b/net/filter-buffer.c index 12e0254..93050f8 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -192,7 +192,7 @@ static void filter_buffer_init(Object *obj) { object_property_add(obj, "interval", "uint32", filter_buffer_get_interval, - filter_buffer_set_interval, NULL, NULL, NULL); + filter_buffer_set_interval, NULL, NULL); } static const TypeInfo filter_buffer_info = { diff --git a/net/filter-mirror.c b/net/filter-mirror.c index d83e815..e9379ce 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -392,12 +392,12 @@ static void filter_mirror_init(Object *obj) MirrorState *s = FILTER_MIRROR(obj); object_property_add_str(obj, "outdev", filter_mirror_get_outdev, - filter_mirror_set_outdev, NULL); + filter_mirror_set_outdev); s->vnet_hdr = false; object_property_add_bool(obj, "vnet_hdr_support", filter_mirror_get_vnet_hdr, - filter_mirror_set_vnet_hdr, NULL); + filter_mirror_set_vnet_hdr); } static void filter_redirector_init(Object *obj) @@ -405,14 +405,14 @@ static void filter_redirector_init(Object *obj) MirrorState *s = FILTER_REDIRECTOR(obj); object_property_add_str(obj, "indev", filter_redirector_get_indev, - filter_redirector_set_indev, NULL); + filter_redirector_set_indev); object_property_add_str(obj, "outdev", filter_redirector_get_outdev, - filter_redirector_set_outdev, NULL); + filter_redirector_set_outdev); s->vnet_hdr = false; object_property_add_bool(obj, "vnet_hdr_support", filter_redirector_get_vnet_hdr, - filter_redirector_set_vnet_hdr, NULL); + filter_redirector_set_vnet_hdr); } static void filter_mirror_fini(Object *obj) diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index 31da08a..1aaad10 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -413,7 +413,7 @@ static void filter_rewriter_init(Object *obj) s->failover_mode = FAILOVER_MODE_OFF; object_property_add_bool(obj, "vnet_hdr_support", filter_rewriter_get_vnet_hdr, - filter_rewriter_set_vnet_hdr, NULL); + filter_rewriter_set_vnet_hdr); } static void colo_rewriter_class_init(ObjectClass *oc, void *data) diff --git a/net/filter.c b/net/filter.c index 8221666..caf6443 100644 --- a/net/filter.c +++ b/net/filter.c @@ -214,21 +214,16 @@ static void netfilter_init(Object *obj) nf->position = g_strdup("tail"); object_property_add_str(obj, "netdev", - netfilter_get_netdev_id, netfilter_set_netdev_id, - NULL); + netfilter_get_netdev_id, netfilter_set_netdev_id); object_property_add_enum(obj, "queue", "NetFilterDirection", &NetFilterDirection_lookup, - netfilter_get_direction, netfilter_set_direction, - NULL); + netfilter_get_direction, netfilter_set_direction); object_property_add_str(obj, "status", - netfilter_get_status, netfilter_set_status, - NULL); + netfilter_get_status, netfilter_set_status); object_property_add_str(obj, "position", - netfilter_get_position, netfilter_set_position, - NULL); + netfilter_get_position, netfilter_set_position); object_property_add_str(obj, "insert", - netfilter_get_insert, netfilter_set_insert, - NULL); + netfilter_get_insert, netfilter_set_insert); } static void netfilter_complete(UserCreatable *uc, Error **errp) |