All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: marcandre.lureau@redhat.com, pbonzini@redhat.com,
	berrange@redhat.com, qemu-devel@nongnu.org, ehabkost@redhat.com
Subject: Re: [PATCH v6] hw/core/qdev: cleanup Error ** variables
Date: Fri, 29 Nov 2019 07:07:38 +0100	[thread overview]
Message-ID: <87a78fz045.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20191127192025.21594-1-vsementsov@virtuozzo.com> (Vladimir Sementsov-Ogievskiy's message of "Wed, 27 Nov 2019 22:20:25 +0300")

Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> Rename Error ** parameter in check_only_migratable to common errp.
>
> In device_set_realized:
>
>  - Move "if (local_err != NULL)" closer to error setters.
>
>  - Drop 'Error **local_errp': it doesn't save any LoCs, but it's very
>    unusual.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>
> v6: enhance grammar in comment [Eric]
>     add r-b by Eric and Marc-André
>
>  hw/core/qdev.c | 28 +++++++++++++---------------
>  1 file changed, 13 insertions(+), 15 deletions(-)
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index cf1ba28fe3..82d3ee590a 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -820,12 +820,12 @@ static bool device_get_realized(Object *obj, Error **errp)
>      return dev->realized;
>  }
>  
> -static bool check_only_migratable(Object *obj, Error **err)
> +static bool check_only_migratable(Object *obj, Error **errp)
>  {
>      DeviceClass *dc = DEVICE_GET_CLASS(obj);
>  
>      if (!vmstate_check_only_migratable(dc->vmsd)) {
> -        error_setg(err, "Device %s is not migratable, but "
> +        error_setg(errp, "Device %s is not migratable, but "
>                     "--only-migratable was specified",
>                     object_get_typename(obj));
>          return false;
> @@ -874,10 +874,9 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
>  
>          if (dc->realize) {
>              dc->realize(dev, &local_err);
> -        }
> -
> -        if (local_err != NULL) {
> -            goto fail;
> +            if (local_err != NULL) {
> +                goto fail;
> +            }
>          }

Yes, this is the more conventional usage.

>  
>          DEVICE_LISTENER_CALL(realize, Forward, dev);
> @@ -918,27 +917,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
>         }
>  
>      } else if (!value && dev->realized) {
> -        Error **local_errp = NULL;
> +        /* We want local_err to track only the first error */
>          QLIST_FOREACH(bus, &dev->child_bus, sibling) {
> -            local_errp = local_err ? NULL : &local_err;
>              object_property_set_bool(OBJECT(bus), false, "realized",
> -                                     local_errp);
> +                                     local_err ? NULL : &local_err);
>          }

This is a rather unusual way to keep the first error of several.
qapi/error.h advises:

 * Receive and accumulate multiple errors (first one wins):
 *     Error *err = NULL, *local_err = NULL;
 *     foo(arg, &err);
 *     bar(arg, &local_err);
 *     error_propagate(&err, local_err);
 *     if (err) {
 *         handle the error...
 *     }

If replacing this by the usual way is too troublesome now, we can do it
after the ERRP_AUTO_PROPAGATE() conversion.  Your choice.

>          if (qdev_get_vmsd(dev)) {
>              vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
>          }
>          if (dc->unrealize) {
> -            local_errp = local_err ? NULL : &local_err;
> -            dc->unrealize(dev, local_errp);
> +            dc->unrealize(dev, local_err ? NULL : &local_err);
>          }
>          dev->pending_deleted_event = true;
>          DEVICE_LISTENER_CALL(unrealize, Reverse, dev);
> -    }
>  
> -    if (local_err != NULL) {
> -        goto fail;
> +        if (local_err != NULL) {
> +            goto fail;
> +        }
>      }
>  
> +    assert(local_err == NULL);

Not sure this one's worth it's keep with the usage of local_err cleaned
up.

>      dev->realized = value;
>      return;
>  
> @@ -976,7 +974,7 @@ static bool device_get_hotpluggable(Object *obj, Error **errp)
>                                  qbus_is_hotpluggable(dev->parent_bus));
>  }
>  
> -static bool device_get_hotplugged(Object *obj, Error **err)
> +static bool device_get_hotplugged(Object *obj, Error **errp)
>  {
>      DeviceState *dev = DEVICE(obj);

In case you want to clean up afterwards rather than now:
Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2019-11-29  6:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 19:20 [PATCH v6] hw/core/qdev: cleanup Error ** variables Vladimir Sementsov-Ogievskiy
2019-11-29  6:07 ` Markus Armbruster [this message]
2019-12-05 14:48   ` Vladimir Sementsov-Ogievskiy
2019-12-05 16:45     ` Eric Blake
2019-12-06  8:26       ` Markus Armbruster
2019-12-06 10:46         ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a78fz045.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.