[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/6] cpu: make cpu_generic_init() abort QEMU on
From: |
Thomas Huth |
Subject: |
Re: [Qemu-devel] [PATCH 2/6] cpu: make cpu_generic_init() abort QEMU on error |
Date: |
Tue, 5 Sep 2017 07:41:51 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
On 04.09.2017 16:00, Igor Mammedov wrote:
> Almost every user of cpu_generic_init() checks for
> returned NULL and then reports failure in a custom way
> and aborts process.
> Some users assume that call can't fail and don't check
> for failure, though they should have checked for it.
>
> In either cases cpu_generic_init() failure is fatal,
> so instead of checking for failure and reporting
> it various ways, make cpu_generic_init() report
> errors in consistent way and terminate QEMU on failure.
>
> Signed-off-by: Igor Mammedov <address@hidden>
> ---
> Even though it's tree wide change, it's trivial so all
> affected call sites are included within one patch.
[...]
> diff --git a/qom/cpu.c b/qom/cpu.c
> index d715890..307d638 100644
> --- a/qom/cpu.c
> +++ b/qom/cpu.c
> @@ -61,7 +61,7 @@ CPUState *cpu_create(const char *typename)
> if (err != NULL) {
> error_report_err(err);
> object_unref(OBJECT(cpu));
> - return NULL;
> + exit(EXIT_FAILURE);
> }
> return cpu;
> }
> @@ -78,8 +78,9 @@ const char *cpu_parse_features(const char *typename, const
> char *cpu_model)
>
> oc = cpu_class_by_name(typename, model_pieces[0]);
> if (oc == NULL) {
> + error_report("unable to find CPU model '%s'", model_pieces[0]);
> g_strfreev(model_pieces);
> - return NULL;
> + exit(EXIT_FAILURE);
> }
>
> cpu_type = object_class_get_name(oc);
> @@ -88,7 +89,7 @@ const char *cpu_parse_features(const char *typename, const
> char *cpu_model)
> g_strfreev(model_pieces);
> if (err != NULL) {
> error_report_err(err);
> - return NULL;
> + exit(EXIT_FAILURE);
> }
> return cpu_type;
> }
> @@ -100,10 +101,8 @@ CPUState *cpu_generic_init(const char *typename, const
> char *cpu_model)
> */
> const char *cpu_type = cpu_parse_features(typename, cpu_model);
>
> - if (cpu_type) {
> - return cpu_create(cpu_type);
> - }
> - return NULL;
> + assert(cpu_type);
> + return cpu_create(cpu_type);
> }
Not sure, but wouldn't it be better to do the error reporting and exit
in cpu_generic_init() instead? In case we ever might want to re-use the
create and parse_feature functions for device_add later (?), and then
the functions must not exit directly anymore...
Thomas
- Re: [Qemu-devel] [PATCH 3/6] cpu: rename cpu_parse_features() to cpu_parse_cpu_model(), (continued)
[Qemu-devel] [PATCH 4/6] vl.c: convert cpu_model to cpu type and set of global properties before machine_init(), Igor Mammedov, 2017/09/04
[Qemu-devel] [PATCH 5/6] pc: use generic cpu_model parsing, Igor Mammedov, 2017/09/04
[Qemu-devel] [PATCH 2/6] cpu: make cpu_generic_init() abort QEMU on error, Igor Mammedov, 2017/09/04
[Qemu-devel] [PATCH 6/6] arm: drop intermadiate cpu_model -> cpu type parsing and use cpu type directly, Igor Mammedov, 2017/09/04