All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	qemu-s390x@nongnu.org, qemu-ppc@nongnu.org,
	qemu-block@nongnu.org, "Cédric Le Goater" <clg@kaod.org>
Subject: Re: [RFC PATCH 5/5] hw/ppc/pnv_bmc: Simplify pnv_bmc_find()
Date: Thu, 23 Feb 2023 16:42:11 +0100	[thread overview]
Message-ID: <871qmgs818.fsf@pond.sub.org> (raw)
In-Reply-To: <20230216122524.67212-6-philmd@linaro.org> ("Philippe Mathieu-Daudé"'s message of "Thu, 16 Feb 2023 13:25:24 +0100")

Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> ForeachArgs::name is only used once as TYPE_IPMI_BMC.
> Since the penultimate commit, object_child_foreach_recursive()'s
> handler takes an Error* argument and return a boolean.
> We can directly pass ForeachArgs::obj as context, removing the
> ForeachArgs structure.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> RFC: please double-check...
>
>  hw/ppc/pnv_bmc.c | 25 +++++++++----------------
>  1 file changed, 9 insertions(+), 16 deletions(-)
>
> diff --git a/hw/ppc/pnv_bmc.c b/hw/ppc/pnv_bmc.c
> index 05acc88a55..566284469f 100644
> --- a/hw/ppc/pnv_bmc.c
> +++ b/hw/ppc/pnv_bmc.c
> @@ -278,36 +278,29 @@ IPMIBmc *pnv_bmc_create(PnvPnor *pnor)
>      return IPMI_BMC(obj);
>  }
>  
> -typedef struct ForeachArgs {
> -    const char *name;
> -    Object *obj;
> -} ForeachArgs;
> -
>  static bool bmc_find(Object *child, void *opaque, Error **errp)
>  {
> -    ForeachArgs *args = opaque;
> +    Object **obj = opaque;
>  
> -    if (object_dynamic_cast(child, args->name)) {
> -        if (args->obj) {
> -            return false;
> +    if (object_dynamic_cast(child, TYPE_IPMI_BMC)) {
> +        if (*obj) {
> +            return true;

Looks like you're changing return false to return true.  Intendional?

>          }
> -        args->obj = child;
> +        *obj = child;
>      }
>      return true;
>  }
>  
>  IPMIBmc *pnv_bmc_find(Error **errp)
>  {
> -    ForeachArgs args = { TYPE_IPMI_BMC, NULL };
> -    int ret;
> +    Object *obj = NULL;
>  
> -    ret = object_child_foreach_recursive(object_get_root(), bmc_find,
> -                                         &args, NULL);
> -    if (ret) {
> +    if (!object_child_foreach_recursive(object_get_root(), bmc_find, &obj,
> +                                        NULL)) {
>          error_setg(errp, "machine should have only one BMC device. "
>                     "Use '-nodefaults'");
>          return NULL;
>      }
>  
> -    return args.obj ? IPMI_BMC(args.obj) : NULL;
> +    return IPMI_BMC(obj);
>  }


      parent reply	other threads:[~2023-02-23 15:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16 12:25 [PATCH 0/5] bulk: Have object_child_foreach() take Error* and return boolean Philippe Mathieu-Daudé
2023-02-16 12:25 ` [PATCH 1/5] hw/nmi: Have nmi_monitor_handler() return a boolean indicating error Philippe Mathieu-Daudé
2023-02-23 15:26   ` Markus Armbruster
2023-02-16 12:25 ` [PATCH 2/5] spapr/ddw: Remove confuse return value in spapr_phb_get_free_liobn() Philippe Mathieu-Daudé
2023-02-17 10:31   ` Daniel Henrique Barboza
2023-02-16 12:25 ` [PATCH 3/5] bulk: Have object_child_foreach() take Error* and return boolean Philippe Mathieu-Daudé
2023-02-16 12:30   ` Michael S. Tsirkin
2023-02-23 15:40   ` Markus Armbruster
2023-02-16 12:25 ` [RFC PATCH 4/5] hw/nmi: Simplify nmi_monitor_handle() and do_nmi() Philippe Mathieu-Daudé
2023-02-16 12:25 ` [RFC PATCH 5/5] hw/ppc/pnv_bmc: Simplify pnv_bmc_find() Philippe Mathieu-Daudé
2023-02-16 18:12   ` Cédric Le Goater
2023-02-16 19:16     ` Philippe Mathieu-Daudé
2023-02-17  8:04       ` Cédric Le Goater
2023-02-23 15:42   ` Markus Armbruster [this message]

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=871qmgs818.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=clg@kaod.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@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 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.