All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	"berrange@redhat.com" <berrange@redhat.com>,
	"ehabkost@redhat.com" <ehabkost@redhat.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"marcandre.lureau@redhat.com" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH v6] hw/core/qdev: cleanup Error ** variables
Date: Fri, 06 Dec 2019 09:26:22 +0100	[thread overview]
Message-ID: <8736dxn9ld.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <61df02c1-2be4-a2fc-e320-c88666b673fc@redhat.com> (Eric Blake's message of "Thu, 5 Dec 2019 10:45:26 -0600")

Eric Blake <eblake@redhat.com> writes:

> On 12/5/19 8:48 AM, Vladimir Sementsov-Ogievskiy wrote:
>
>>>> @@ -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.
>
> It may be unusual, but has the benefit of avoiding error_propagate...

Non-issue if the error_propagate() gets replaced by
ERRP_AUTO_PROPAGATE(), isn't it?

>>> 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...
>>>    *     }
>>
>> Hmm, honestly, I like more what I've written:
>>
>> 1. less code
>> 2. logic is more clean: we store first error to local_err, and after first error
>>      pass NULL as a parameter. No propagation or extra error variables.
>> 3. more efficient (no propagation, no extra allocation for errors which we'll drop
>>      anyway) (I understand that efficiency of error path is not thing to care about,
>>      so it's at third place)
>>
>> Also, propagation which you propose is also unusual thing (it proposed in comment,
>> but who reads it :). I've never seen it before, and I've to go and check that
>> error_propagate works correctly when first argument is already set.

When you think you can improve on the common, documented pattern, you're
invited to update the documentation and the existing uses of the
pattern.

If everybody "improved" on common, documented patterns locally, the code
would become needlessly hard to read for developers with experience in
the pattern's area.

>> So, I'd prefer to keep now this patch as is, and to convert later if we really need it.

I want this to match the common, documented pattern.  Whether we make it
match before or after your ERRP_AUTO_PROPAGATE() work doesn't matter to
me.

>>> If replacing this by the usual way is too troublesome now, we can do it
>>> after the ERRP_AUTO_PROPAGATE() conversion.  Your choice.
>
> ...and after conversion to use ERRP_AUTO_PROPATATE(), the use of
> error_propagate() should NOT occur in any code _except_ for the macro
> definition (any other use of the function points out a place where we
> failed to use the macro to get rid of boilerplate).

I figure we still need it in the (rare) cases where we want to ignore
some of a function's errors, as we do in fit_load_fdt().  If that
bothers us, we can try to find a solution that avoids the boilerplate.



  reply	other threads:[~2019-12-06 15:31 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
2019-12-05 14:48   ` Vladimir Sementsov-Ogievskiy
2019-12-05 16:45     ` Eric Blake
2019-12-06  8:26       ` Markus Armbruster [this message]
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=8736dxn9ld.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@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.