All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, "Kevin Wolf" <kwolf@redhat.com>,
	"Fam Zheng" <fam@euphon.net>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"open list:Dirty Bitmaps" <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"open list:Trivial patches" <qemu-trivial@nongnu.org>,
	"Michael Roth" <michael.roth@amd.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Max Reitz" <mreitz@redhat.com>,
	"Michael Tokarev" <mjt@tls.msk.ru>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Laurent Vivier" <laurent@vivier.eu>
Subject: Re: [PATCH v3 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases
Date: Wed, 13 Jan 2021 14:16:46 +0100	[thread overview]
Message-ID: <87v9c1yo1t.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201223221102.390740-7-eblake@redhat.com> (Eric Blake's message of "Wed, 23 Dec 2020 16:11:01 -0600")

Eric Blake <eblake@redhat.com> writes:

> The easiest spots to use QAPI_LIST_APPEND are where we already have an
> obvious pointer to the tail of a list.  While at it, consistently use
> the variable name 'tail' for that purpose.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
[...]
> diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> index 6350caa76530..3f3182007b07 100644
> --- a/hw/acpi/cpu.c
> +++ b/hw/acpi/cpu.c
> @@ -42,16 +42,12 @@ static ACPIOSTInfo *acpi_cpu_device_status(int idx, AcpiCpuStatus *cdev)
>      return info;
>  }
>
> -void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list)
> +void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***tail)
>  {
>      int i;

Sure you want to rename the parameter?  What about:

   void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list)
   {
  +    ACPIOSTInfoList ***tail = list;
       int i;

>
>      for (i = 0; i < cpu_st->dev_count; i++) {
> -        ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1);
> -        elem->value = acpi_cpu_device_status(i, &cpu_st->devs[i]);
> -        elem->next = NULL;
> -        **list = elem;
> -        *list = &elem->next;
> +        QAPI_LIST_APPEND(*tail, acpi_cpu_device_status(i, &cpu_st->devs[i]));
>      }
>  }
>
> diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
> index f2552b2a4624..e4b836bd5e46 100644
> --- a/hw/acpi/memory_hotplug.c
> +++ b/hw/acpi/memory_hotplug.c
> @@ -51,16 +51,13 @@ static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev)
>      return info;
>  }
>
> -void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list)
> +void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***tail)

Likewise.

>  {
>      int i;
>
>      for (i = 0; i < mem_st->dev_count; i++) {
> -        ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1);
> -        elem->value = acpi_memory_device_status(i, &mem_st->devs[i]);
> -        elem->next = NULL;
> -        **list = elem;
> -        *list = &elem->next;
> +        QAPI_LIST_APPEND(*tail,
> +                         acpi_memory_device_status(i, &mem_st->devs[i]));
>      }
>  }
>
[...]
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 35459a38bb1c..95326285b76d 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -4817,20 +4817,17 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose);
>
>  /* Build a list with the name of all features on a feature word array */
>  static void x86_cpu_list_feature_names(FeatureWordArray features,
> -                                       strList **feat_names)
> +                                       strList **tail)

Likewise.

>  {
>      FeatureWord w;
> -    strList **next = feat_names;
>
>      for (w = 0; w < FEATURE_WORDS; w++) {
>          uint64_t filtered = features[w];
>          int i;
>          for (i = 0; i < 64; i++) {
>              if (filtered & (1ULL << i)) {
> -                strList *new = g_new0(strList, 1);
> -                new->value = g_strdup(x86_cpu_feature_name(w, i));
> -                *next = new;
> -                next = &new->next;
> +                QAPI_LIST_APPEND(tail,
> +                                 g_strdup(x86_cpu_feature_name(w, i)));
>              }
>          }
>      }
> @@ -4851,16 +4848,13 @@ static void x86_cpu_get_unavailable_features(Object *obj, Visitor *v,
>   * running using the current machine and accelerator.
>   */
>  static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
> -                                                 strList **missing_feats)
> +                                                 strList **tail)

Likewise.

>  {
>      X86CPU *xc;
>      Error *err = NULL;
> -    strList **next = missing_feats;
>
>      if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) {
> -        strList *new = g_new0(strList, 1);
> -        new->value = g_strdup("kvm");
> -        *missing_feats = new;
> +        QAPI_LIST_APPEND(tail, g_strdup("kvm"));
>          return;
>      }
>
> @@ -4872,16 +4866,13 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
>           * but in case it does, just report the model as not
>           * runnable at all using the "type" property.
>           */
> -        strList *new = g_new0(strList, 1);
> -        new->value = g_strdup("type");
> -        *next = new;
> -        next = &new->next;
> +        QAPI_LIST_APPEND(tail, g_strdup("type"));
>          error_free(err);
>      }
>
>      x86_cpu_filter_features(xc, false);
>
> -    x86_cpu_list_feature_names(xc->filtered_features, next);
> +    x86_cpu_list_feature_names(xc->filtered_features, tail);
>
>      object_unref(OBJECT(xc));
>  }
[...]

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



WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"open list:Dirty Bitmaps" <qemu-block@nongnu.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"open list:Trivial patches" <qemu-trivial@nongnu.org>,
	"Michael Roth" <michael.roth@amd.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
	"Michael Tokarev" <mjt@tls.msk.ru>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"John Snow" <jsnow@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Laurent Vivier" <laurent@vivier.eu>
Subject: Re: [PATCH v3 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases
Date: Wed, 13 Jan 2021 14:16:46 +0100	[thread overview]
Message-ID: <87v9c1yo1t.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201223221102.390740-7-eblake@redhat.com> (Eric Blake's message of "Wed, 23 Dec 2020 16:11:01 -0600")

Eric Blake <eblake@redhat.com> writes:

> The easiest spots to use QAPI_LIST_APPEND are where we already have an
> obvious pointer to the tail of a list.  While at it, consistently use
> the variable name 'tail' for that purpose.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
[...]
> diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c
> index 6350caa76530..3f3182007b07 100644
> --- a/hw/acpi/cpu.c
> +++ b/hw/acpi/cpu.c
> @@ -42,16 +42,12 @@ static ACPIOSTInfo *acpi_cpu_device_status(int idx, AcpiCpuStatus *cdev)
>      return info;
>  }
>
> -void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list)
> +void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***tail)
>  {
>      int i;

Sure you want to rename the parameter?  What about:

   void acpi_cpu_ospm_status(CPUHotplugState *cpu_st, ACPIOSTInfoList ***list)
   {
  +    ACPIOSTInfoList ***tail = list;
       int i;

>
>      for (i = 0; i < cpu_st->dev_count; i++) {
> -        ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1);
> -        elem->value = acpi_cpu_device_status(i, &cpu_st->devs[i]);
> -        elem->next = NULL;
> -        **list = elem;
> -        *list = &elem->next;
> +        QAPI_LIST_APPEND(*tail, acpi_cpu_device_status(i, &cpu_st->devs[i]));
>      }
>  }
>
> diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
> index f2552b2a4624..e4b836bd5e46 100644
> --- a/hw/acpi/memory_hotplug.c
> +++ b/hw/acpi/memory_hotplug.c
> @@ -51,16 +51,13 @@ static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev)
>      return info;
>  }
>
> -void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list)
> +void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***tail)

Likewise.

>  {
>      int i;
>
>      for (i = 0; i < mem_st->dev_count; i++) {
> -        ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1);
> -        elem->value = acpi_memory_device_status(i, &mem_st->devs[i]);
> -        elem->next = NULL;
> -        **list = elem;
> -        *list = &elem->next;
> +        QAPI_LIST_APPEND(*tail,
> +                         acpi_memory_device_status(i, &mem_st->devs[i]));
>      }
>  }
>
[...]
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 35459a38bb1c..95326285b76d 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -4817,20 +4817,17 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool verbose);
>
>  /* Build a list with the name of all features on a feature word array */
>  static void x86_cpu_list_feature_names(FeatureWordArray features,
> -                                       strList **feat_names)
> +                                       strList **tail)

Likewise.

>  {
>      FeatureWord w;
> -    strList **next = feat_names;
>
>      for (w = 0; w < FEATURE_WORDS; w++) {
>          uint64_t filtered = features[w];
>          int i;
>          for (i = 0; i < 64; i++) {
>              if (filtered & (1ULL << i)) {
> -                strList *new = g_new0(strList, 1);
> -                new->value = g_strdup(x86_cpu_feature_name(w, i));
> -                *next = new;
> -                next = &new->next;
> +                QAPI_LIST_APPEND(tail,
> +                                 g_strdup(x86_cpu_feature_name(w, i)));
>              }
>          }
>      }
> @@ -4851,16 +4848,13 @@ static void x86_cpu_get_unavailable_features(Object *obj, Visitor *v,
>   * running using the current machine and accelerator.
>   */
>  static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
> -                                                 strList **missing_feats)
> +                                                 strList **tail)

Likewise.

>  {
>      X86CPU *xc;
>      Error *err = NULL;
> -    strList **next = missing_feats;
>
>      if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) {
> -        strList *new = g_new0(strList, 1);
> -        new->value = g_strdup("kvm");
> -        *missing_feats = new;
> +        QAPI_LIST_APPEND(tail, g_strdup("kvm"));
>          return;
>      }
>
> @@ -4872,16 +4866,13 @@ static void x86_cpu_class_check_missing_features(X86CPUClass *xcc,
>           * but in case it does, just report the model as not
>           * runnable at all using the "type" property.
>           */
> -        strList *new = g_new0(strList, 1);
> -        new->value = g_strdup("type");
> -        *next = new;
> -        next = &new->next;
> +        QAPI_LIST_APPEND(tail, g_strdup("type"));
>          error_free(err);
>      }
>
>      x86_cpu_filter_features(xc, false);
>
> -    x86_cpu_list_feature_names(xc->filtered_features, next);
> +    x86_cpu_list_feature_names(xc->filtered_features, tail);
>
>      object_unref(OBJECT(xc));
>  }
[...]

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



  parent reply	other threads:[~2021-01-13 13:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23 22:10 [PATCH v3 0/7] Common macros for QAPI list growth Eric Blake
2020-12-23 22:10 ` [PATCH v3 1/7] net: Clarify early exit condition Eric Blake
2021-01-13 12:57   ` Markus Armbruster
2020-12-23 22:10 ` [PATCH v3 2/7] rocker: Revamp fp_port_get_info Eric Blake
2021-01-13 12:57   ` Markus Armbruster
2020-12-23 22:10 ` [PATCH v3 3/7] migration: Refactor migrate_cap_add Eric Blake
2021-01-13 12:58   ` Markus Armbruster
2020-12-23 22:10 ` [PATCH v3 4/7] qapi: Use QAPI_LIST_PREPEND() where possible Eric Blake
2020-12-23 22:10   ` Eric Blake
2021-01-13 13:00   ` Markus Armbruster
2020-12-23 22:11 ` [PATCH v3 5/7] qapi: Introduce QAPI_LIST_APPEND Eric Blake
2020-12-24  6:14   ` Vladimir Sementsov-Ogievskiy
2021-01-13 13:04   ` Markus Armbruster
2021-01-13 14:08     ` Eric Blake
2020-12-23 22:11 ` [PATCH v3 6/7] qapi: Use QAPI_LIST_APPEND in trivial cases Eric Blake
2020-12-23 22:11   ` Eric Blake
2020-12-24  9:56   ` Vladimir Sementsov-Ogievskiy
2020-12-24  9:56     ` Vladimir Sementsov-Ogievskiy
2021-01-13 14:10     ` Eric Blake
2021-01-13 14:10       ` Eric Blake
2021-01-13 13:16   ` Markus Armbruster [this message]
2021-01-13 13:16     ` Markus Armbruster
2021-01-13 14:11     ` Eric Blake
2021-01-13 14:11       ` Eric Blake
2020-12-23 22:11 ` [PATCH v3 7/7] qapi: More complex uses of QAPI_LIST_APPEND Eric Blake
2020-12-24 11:35   ` Vladimir Sementsov-Ogievskiy
2021-01-13 13:31   ` 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=87v9c1yo1t.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=fam@euphon.net \
    --cc=imammedo@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=laurent@vivier.eu \
    --cc=michael.roth@amd.com \
    --cc=mjt@tls.msk.ru \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=richard.henderson@linaro.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.