qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Gavin Shan <gshan@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v4 28/33] machine: Print CPU model name instead of CPU type name
Date: Wed, 1 Nov 2023 22:06:39 -0700	[thread overview]
Message-ID: <9a9202ee-f609-4746-b400-7c99bfc078e1@linaro.org> (raw)
In-Reply-To: <20231102002500.1750692-29-gshan@redhat.com>

On 11/1/23 17:24, Gavin Shan wrote:
> The names of supported CPU models instead of CPU types should be
> printed when the user specified CPU type isn't supported, to be
> consistent with the output from '-cpu ?'.
> 
> Correct the error messages to print CPU model names instead of CPU
> type names.
> 
> Signed-off-by: Gavin Shan <gshan@redhat.com>
> ---
>   hw/core/machine.c | 19 +++++++++++++++----
>   1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 2d78692df1..1dd0f8831b 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -1391,6 +1391,7 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp)
>       MachineClass *mc = MACHINE_GET_CLASS(machine);
>       ObjectClass *oc = object_class_by_name(machine->cpu_type);
>       CPUClass *cc;
> +    char *model;

No need for this outside...


>       int i;
>   
>       /*
> @@ -1407,11 +1408,21 @@ static void is_cpu_type_supported(MachineState *machine, Error **errp)
>   
>           /* The user specified CPU type isn't valid */
>           if (!mc->valid_cpu_types[i]) {

... this block.

> -            error_setg(errp, "Invalid CPU type: %s", machine->cpu_type);
> -            error_append_hint(errp, "The valid types are: %s",
> -                              mc->valid_cpu_types[0]);
> +            model = cpu_model_from_type(machine->cpu_type);
> +            g_assert(model != NULL);
> +            error_setg(errp, "Invalid CPU type: %s", model);
> +            g_free(model);
> +
> +            model = cpu_model_from_type(mc->valid_cpu_types[0]);
> +            g_assert(model != NULL);
> +            error_append_hint(errp, "The valid types are: %s", model);
> +            g_free(model);
> +
>               for (i = 1; mc->valid_cpu_types[i]; i++) {
> -                error_append_hint(errp, ", %s", mc->valid_cpu_types[i]);
> +                model = cpu_model_from_type(mc->valid_cpu_types[i]);
> +                g_assert(model != NULL);
> +                error_append_hint(errp, ", %s", model);
> +                g_free(model);
>               }

I really don't like all of the replicated asserts for non-null.

You already know there's no path through cpu_model_from_type that doesn't return 
something...  And anyway, in extremis, "(nil)" will print just fine.


r~


  reply	other threads:[~2023-11-02  5:07 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02  0:24 [PATCH v4 00/33] Unified CPU type check Gavin Shan
2023-11-02  0:24 ` [PATCH v4 01/33] target/alpha: Tidy up alpha_cpu_class_by_name() Gavin Shan
2023-11-06 14:22   ` Igor Mammedov
2023-11-13 23:23     ` Gavin Shan
2023-11-02  0:24 ` [PATCH v4 02/33] hw/cpu: Call object_class_is_abstract() once in cpu_class_by_name() Gavin Shan
2023-11-06 14:40   ` Igor Mammedov
2023-11-13 23:46     ` Gavin Shan
2023-11-02  0:24 ` [PATCH v4 03/33] cpu: Call object_class_dynamic_cast() " Gavin Shan
2023-11-06 14:48   ` Igor Mammedov
2023-11-02  0:24 ` [PATCH v4 04/33] cpu: Add helper cpu_model_from_type() Gavin Shan
2023-11-02  0:24 ` [PATCH v4 05/33] target/alpha: Use generic helper to show CPU model names Gavin Shan
2023-11-02  0:24 ` [PATCH v4 06/33] target/arm: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 07/33] target/avr: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 08/33] target/cris: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 09/33] target/hexagon: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 10/33] target/i386: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 11/33] target/loongarch: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 12/33] target/m68k: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 13/33] target/mips: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 14/33] target/openrisc: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 15/33] target/ppc: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 16/33] target/riscv: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 17/33] target/rx: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 18/33] target/s390x: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 19/33] target/sh4: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 20/33] target/tricore: " Gavin Shan
2023-11-02  0:24 ` [PATCH v4 21/33] target/hppa: Implement hppa_cpu_list() Gavin Shan
2023-11-02  0:24 ` [PATCH v4 22/33] target/microblaze: Implement microblaze_cpu_list() Gavin Shan
2023-11-02  0:24 ` [PATCH v4 23/33] target/nios2: Implement nios2_cpu_list() Gavin Shan
2023-11-02  0:24 ` [PATCH v4 24/33] cpu: Mark cpu_list() supported on all targets Gavin Shan
2023-11-02  0:24 ` [PATCH v4 25/33] machine: Constify MachineClass::valid_cpu_types[i] Gavin Shan
2023-11-02  4:14   ` Richard Henderson
2023-11-02  0:24 ` [PATCH v4 26/33] machine: Use error handling when CPU type is checked Gavin Shan
2023-11-02  4:57   ` Richard Henderson
2023-11-02  0:24 ` [PATCH v4 27/33] machine: Introduce helper is_cpu_type_supported() Gavin Shan
2023-11-02  5:02   ` Richard Henderson
2023-11-02  0:24 ` [PATCH v4 28/33] machine: Print CPU model name instead of CPU type name Gavin Shan
2023-11-02  5:06   ` Richard Henderson [this message]
2023-11-02  0:24 ` [PATCH v4 29/33] hw/arm/virt: Check CPU type in machine_run_board_init() Gavin Shan
2023-11-02  5:09   ` Richard Henderson
2023-11-02  0:24 ` [PATCH v4 30/33] hw/arm/virt: Hide host CPU model for tcg Gavin Shan
2023-11-02  5:10   ` Richard Henderson
2023-11-02  0:24 ` [PATCH v4 31/33] hw/arm/sbsa-ref: Check CPU type in machine_run_board_init() Gavin Shan
2023-11-02  5:15   ` Richard Henderson
2023-11-02  0:24 ` [PATCH v4 32/33] hw/arm: " Gavin Shan
2023-11-02  5:17   ` Richard Henderson
2023-11-02  0:25 ` [PATCH v4 33/33] hw/riscv/shakti_c: " Gavin Shan
2023-11-02  5:19   ` Richard Henderson

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=9a9202ee-f609-4746-b400-7c99bfc078e1@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=gshan@redhat.com \
    --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 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).