From 4482e05cbbb7e50e476f6a9500cf0b38913bd939 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Wed, 13 Sep 2017 18:04:54 +0200 Subject: cpu: make cpu_generic_init() abort QEMU on error 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 Reviewed-by: Philippe Mathieu-Daudé Message-Id: <1505318697-77161-3-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost --- qom/cpu.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'qom') diff --git a/qom/cpu.c b/qom/cpu.c index 483f26a5fb..94fa8fe005 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -62,7 +62,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; } @@ -71,7 +71,6 @@ const char *cpu_parse_cpu_model(const char *typename, const char *cpu_model) { ObjectClass *oc; CPUClass *cc; - Error *err = NULL; gchar **model_pieces; const char *cpu_type; @@ -79,18 +78,15 @@ const char *cpu_parse_cpu_model(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); cc = CPU_CLASS(oc); - cc->parse_features(cpu_type, model_pieces[1], &err); + cc->parse_features(cpu_type, model_pieces[1], &error_fatal); g_strfreev(model_pieces); - if (err != NULL) { - error_report_err(err); - return NULL; - } return cpu_type; } @@ -99,12 +95,7 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model) /* TODO: all callers of cpu_generic_init() need to be converted to * call cpu_parse_features() only once, before calling cpu_generic_init(). */ - const char *cpu_type = cpu_parse_cpu_model(typename, cpu_model); - - if (cpu_type) { - return cpu_create(cpu_type); - } - return NULL; + return cpu_create(cpu_parse_cpu_model(typename, cpu_model)); } bool cpu_paging_enabled(const CPUState *cpu) -- cgit v1.2.3-55-g7522