From: David Gibson <david@gibson.dropbear.id.au>
To: Markus Armbruster <armbru@redhat.com>
Cc: Greg Kurz <groug@kaod.org>, Laurent Vivier <lvivier@redhat.com>,
Cedric Le Goater <clg@kaod.org>,
qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
Bharata B Rao <bharata@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/4] spapr: fix error reporting in xics_system_init()
Date: Mon, 22 May 2017 19:00:55 +1000 [thread overview]
Message-ID: <20170522090055.GN30246@umbus.fritz.box> (raw)
In-Reply-To: <87lgpp2v9f.fsf@dusky.pond.sub.org>
[-- Attachment #1: Type: text/plain, Size: 5182 bytes --]
On Mon, May 22, 2017 at 09:41:48AM +0200, Markus Armbruster wrote:
> Greg Kurz <groug@kaod.org> writes:
>
> > On Sat, 20 May 2017 16:45:09 +1000
> > David Gibson <david@gibson.dropbear.id.au> wrote:
> >
> >> On Fri, May 19, 2017 at 12:32:12PM +0200, Greg Kurz wrote:
> >> > If the user explicitely asked for kernel-irqchip support and "xics-kvm"
> >> > initialization fails, we shouldn't fallback to emulated "xics" as we
> >> > do now. It is also awkward to print an error message when we have an
> >> > errp pointer argument.
> >> >
> >> > Let's use the errp argument to report the error and let the caller decide.
> >> > This simplifies the code as we don't need a local Error * here.
> >> >
> >> > Signed-off-by: Greg Kurz <groug@kaod.org>
> >>
> >> Concept looks good, but..
> >>
> >> > ---
> >> > v2: - total rewrite
> >> > ---
> >> > hw/ppc/spapr.c | 13 ++++++-------
> >> > 1 file changed, 6 insertions(+), 7 deletions(-)
> >> >
> >> > diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> >> > index 91f7434861a8..75e298b4c6be 100644
> >> > --- a/hw/ppc/spapr.c
> >> > +++ b/hw/ppc/spapr.c
> >> > @@ -128,18 +128,14 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)
> >> > sPAPRMachineState *spapr = SPAPR_MACHINE(machine);
> >> >
> >> > if (kvm_enabled()) {
> >> > - Error *err = NULL;
> >> > -
> >> > if (machine_kernel_irqchip_allowed(machine) &&
> >> > !xics_kvm_init(spapr, errp)) {
> >> > spapr->icp_type = TYPE_KVM_ICP;
> >> > - spapr->ics = spapr_ics_create(spapr, TYPE_ICS_KVM, nr_irqs, &err);
> >> > + spapr->ics = spapr_ics_create(spapr, TYPE_ICS_KVM, nr_irqs, errp);
> >>
> >> I believe there are reasons you're not supposed to just pass an errp
> >> through to a subordinate function. Instead you're supposed to have a
> >> local Error * and use error_propagate().
> >>
> >
> > You only need to have a local Error * if it is used to check the return status
> > of the function (ie, you cannot check *errp because errp could be NULL) as
> > described in error.h.
>
> Correct. Quote:
>
> * Receive an error and pass it on to the caller:
> * Error *err = NULL;
> * foo(arg, &err);
> * if (err) {
> * handle the error...
> * error_propagate(errp, err);
> * }
> * where Error **errp is a parameter, by convention the last one.
> *
> * Do *not* "optimize" this to
> * foo(arg, errp);
> * if (*errp) { // WRONG!
> * handle the error...
> * }
> * because errp may be NULL!
> *
> * But when all you do with the error is pass it on, please use
> * foo(arg, errp);
> * for readability.
So, I already merged based on Greg's comment, but it's nice to have
confirmation; thanks Markus.
> > This isn't the case here but...
> >
> >> > }
> >> > if (machine_kernel_irqchip_required(machine) && !spapr->ics) {
> >> > - error_reportf_err(err,
> >> > - "kernel_irqchip requested but unavailable: ");
> >> > - } else {
> >> > - error_free(err);
> >> > + error_prepend(errp, "kernel_irqchip requested but unavailable: ");
> >> > + return;
> >> > }
> >> > }
> >> >
> >> > @@ -147,6 +143,9 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp)
> >> > xics_spapr_init(spapr);
> >> > spapr->icp_type = TYPE_ICP;
> >> > spapr->ics = spapr_ics_create(spapr, TYPE_ICS_SIMPLE, nr_irqs, errp);
> >> > + if (!spapr->ics) {
> >>
> >> It would also be more standard to check the returned error, rather
> >> than the other result.
> >>
> >
> > ... if you prefer to use a local Error *, I'll gladly do that. :)
>
> Opinions and practice vary on this one.
>
> I prefer checking the return value because it lets me avoid the
> error_propagate() boiler-plate more often.
Noted for future reference.
> Having both an Error parameter and an error return value begs the
> question whether the two agree.
[Irrelevant aside: this is not what "begging the question" means. Or
at least, it's not what it used to mean; it's probably a lost cause
at this point, even with those who don't get a free pass for being
non-native speakers. https://en.wikipedia.org/wiki/Begging_the_question]
> You can assert they do, but it's distracting. We generally don't.
>
> When there's no success value to transmit, you avoid the problem by
> making the function return void. We used to favor that, but it has
> turned out not to be a success, because it leads to cumbersome code.
> For what it's worth, GLib wants you to transmit success / failure in the
> return value, too:
>
> https://developer.gnome.org/glib/unstable/glib-Error-Reporting.html#gerror-rules
Also noted, thanks.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2017-05-22 9:01 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-19 10:31 [Qemu-devel] [PATCH v2 0/4] spapr/xics: fix migration of older machine types Greg Kurz
2017-05-19 10:32 ` [Qemu-devel] [PATCH v2 1/4] spapr_cpu_core: drop reference on ICP object during CPU realization Greg Kurz
2017-05-20 6:40 ` David Gibson
2017-05-19 10:32 ` [Qemu-devel] [PATCH v2 2/4] spapr: fix error reporting in xics_system_init() Greg Kurz
2017-05-20 6:45 ` David Gibson
2017-05-21 17:03 ` Greg Kurz
2017-05-22 1:26 ` David Gibson
2017-05-22 7:41 ` Markus Armbruster
2017-05-22 9:00 ` David Gibson [this message]
2017-05-19 10:32 ` [Qemu-devel] [PATCH v2 3/4] target/ppc: consolidate CPU device-tree id computation in helper Greg Kurz
2017-05-22 2:04 ` David Gibson
2017-05-22 2:12 ` David Gibson
2017-05-22 9:09 ` Greg Kurz
2017-05-22 14:33 ` Greg Kurz
2017-05-23 2:37 ` David Gibson
2017-05-22 8:59 ` Greg Kurz
2017-05-22 13:13 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2017-05-23 6:37 ` David Gibson
2017-05-23 2:35 ` [Qemu-devel] " David Gibson
2017-05-23 6:57 ` Greg Kurz
2017-05-19 10:32 ` [Qemu-devel] [PATCH v2 4/4] spapr: fix migration of ICP objects from/to older QEMU Greg Kurz
2017-05-22 2:30 ` David Gibson
2017-05-22 7:20 ` Cédric Le Goater
2017-05-22 9:15 ` David Gibson
2017-05-22 15:04 ` Greg Kurz
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=20170522090055.GN30246@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=armbru@redhat.com \
--cc=bharata@linux.vnet.ibm.com \
--cc=clg@kaod.org \
--cc=groug@kaod.org \
--cc=lvivier@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).