From 778a2dc59213d789f5bf8409547b529af4eb9ead Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 7 Jul 2020 18:05:56 +0200 Subject: qom: Use returned bool to check for failure, Coccinelle part The previous commit enables conversion of foo(..., &err); if (err) { ... } to if (!foo(..., errp)) { ... } for QOM functions that now return true / false on success / error. Coccinelle script: @@ identifier fun = { object_apply_global_props, object_initialize_child_with_props, object_initialize_child_with_propsv, object_property_get, object_property_get_bool, object_property_parse, object_property_set, object_property_set_bool, object_property_set_int, object_property_set_link, object_property_set_qobject, object_property_set_str, object_property_set_uint, object_set_props, object_set_propv, user_creatable_add_dict, user_creatable_complete, user_creatable_del }; expression list args, args2; typedef Error; Error *err; @@ - fun(args, &err, args2); - if (err) + if (!fun(args, &err, args2)) { ... } Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by ARMSSE being used both as typedef and function-like macro there. Convert manually. Line breaks tidied up manually. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200707160613.848843-29-armbru@redhat.com> --- hw/virtio/virtio-rng.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'hw/virtio/virtio-rng.c') diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index 85f7163e2d..8d052fbeed 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -194,9 +194,8 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp) if (vrng->conf.rng == NULL) { Object *default_backend = object_new(TYPE_RNG_BUILTIN); - user_creatable_complete(USER_CREATABLE(default_backend), - &local_err); - if (local_err) { + if (!user_creatable_complete(USER_CREATABLE(default_backend), + &local_err)) { error_propagate(errp, local_err); object_unref(default_backend); return; -- cgit v1.2.3