All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>, Jiri Pirko <jiri@resnulli.us>,
	qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [PATCH v2 2/7] rocker: Revamp fp_port_get_info
Date: Tue, 17 Nov 2020 10:27:09 +0100	[thread overview]
Message-ID: <87pn4c9vv6.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201113011340.463563-3-eblake@redhat.com> (Eric Blake's message of "Thu, 12 Nov 2020 19:13:35 -0600")

Eric Blake <eblake@redhat.com> writes:

> Instead of modifying the value member of a list element passed as a
> parameter, and open-coding the manipulation of that list, it's nicer
> to just return a freshly allocated value to be prepended to a list
> using QAPI_LIST_PREPEND.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  hw/net/rocker/rocker_fp.h |  2 +-
>  hw/net/rocker/rocker.c    |  8 +-------
>  hw/net/rocker/rocker_fp.c | 17 ++++++++++-------
>  3 files changed, 12 insertions(+), 15 deletions(-)
>
> diff --git a/hw/net/rocker/rocker_fp.h b/hw/net/rocker/rocker_fp.h
> index dbe1dd329a4b..7ff57aac0180 100644
> --- a/hw/net/rocker/rocker_fp.h
> +++ b/hw/net/rocker/rocker_fp.h
> @@ -28,7 +28,7 @@ int fp_port_eg(FpPort *port, const struct iovec *iov, int iovcnt);
>
>  char *fp_port_get_name(FpPort *port);
>  bool fp_port_get_link_up(FpPort *port);
> -void fp_port_get_info(FpPort *port, RockerPortList *info);
> +RockerPort *fp_port_get_info(FpPort *port);
>  void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr);
>  void fp_port_set_macaddr(FpPort *port, MACAddr *macaddr);
>  uint8_t fp_port_get_learning(FpPort *port);
> diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
> index 1af1e6fa2f9b..c53a02315e54 100644
> --- a/hw/net/rocker/rocker.c
> +++ b/hw/net/rocker/rocker.c
> @@ -127,13 +127,7 @@ RockerPortList *qmp_query_rocker_ports(const char *name, Error **errp)
>      }
>
>      for (i = r->fp_ports - 1; i >= 0; i--) {
> -        RockerPortList *info = g_malloc0(sizeof(*info));
> -        info->value = g_malloc0(sizeof(*info->value));
> -        struct fp_port *port = r->fp_port[i];
> -
> -        fp_port_get_info(port, info);
> -        info->next = list;
> -        list = info;
> +        QAPI_LIST_PREPEND(list, fp_port_get_info(r->fp_port[i]));

Relies on QAPI_LIST_PREPEND() evaluating its second argument exactly
once.  Part of its written contract; okay.

>      }
>
>      return list;
> diff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c
> index 4aa7da79b81d..cbeed65bd5ec 100644
> --- a/hw/net/rocker/rocker_fp.c
> +++ b/hw/net/rocker/rocker_fp.c
> @@ -51,14 +51,17 @@ bool fp_port_get_link_up(FpPort *port)
>      return !qemu_get_queue(port->nic)->link_down;
>  }
>
> -void fp_port_get_info(FpPort *port, RockerPortList *info)
> +RockerPort *fp_port_get_info(FpPort *port)
>  {
> -    info->value->name = g_strdup(port->name);
> -    info->value->enabled = port->enabled;
> -    info->value->link_up = fp_port_get_link_up(port);
> -    info->value->speed = port->speed;
> -    info->value->duplex = port->duplex;
> -    info->value->autoneg = port->autoneg;
> +    RockerPort *value = g_malloc0(sizeof(*value));
> +
> +    value->name = g_strdup(port->name);
> +    value->enabled = port->enabled;
> +    value->link_up = fp_port_get_link_up(port);
> +    value->speed = port->speed;
> +    value->duplex = port->duplex;
> +    value->autoneg = port->autoneg;
> +    return value;
>  }
>
>  void fp_port_get_macaddr(FpPort *port, MACAddr *macaddr)

Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2020-11-17  9:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13  1:13 [PATCH v2 0/7] Common macros for QAPI list growth Eric Blake
2020-11-13  1:13 ` [PATCH v2 1/7 for-5.2?] net: Fix memory leak on error Eric Blake
2020-11-16 14:22   ` Markus Armbruster
2020-11-16 14:41     ` Eric Blake
2020-11-13  1:13 ` [PATCH v2 2/7] rocker: Revamp fp_port_get_info Eric Blake
2020-11-17  9:27   ` Markus Armbruster [this message]
2020-11-13  1:13 ` [PATCH v2 3/7] migration: Refactor migrate_cap_add Eric Blake
2020-11-17  9:45   ` Markus Armbruster
2020-11-13  1:13 ` [PATCH v2 4/7] qapi: Use QAPI_LIST_PREPEND() where possible Eric Blake
2020-11-17 10:20   ` Markus Armbruster
2020-11-17 11:45   ` Stefan Hajnoczi
2020-11-13  1:13 ` [PATCH v2 5/7] qapi: Introduce QAPI_LIST_APPEND Eric Blake
2020-11-17 12:51   ` Markus Armbruster
2020-11-18  0:41     ` Eric Blake
2020-11-18  6:21       ` Markus Armbruster
2020-11-13  1:13 ` [PATCH v2 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases Eric Blake
2020-11-13  1:13 ` [PATCH v2 7/7] qapi: More complex uses of QAPI_LIST_APPEND Eric Blake
2020-11-13 19:39   ` Dr. David Alan Gilbert
2020-11-16 13:27     ` Eric Blake
2020-11-19  8:50   ` Markus Armbruster
2020-12-04 22:54     ` Eric Blake
2020-11-19  9:28 ` [PATCH v2 0/7] Common macros for QAPI list growth Markus Armbruster
2020-12-19  9:43   ` Markus Armbruster

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=87pn4c9vv6.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=qemu-devel@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.