From patchwork Fri Dec 28 20:33:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 208593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 347232C00DE for ; Sat, 29 Dec 2012 08:18:59 +1100 (EST) Received: from localhost ([::1]:36637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogcI-0002He-ND for incoming@patchwork.ozlabs.org; Fri, 28 Dec 2012 15:33:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogbZ-0000eH-Fx for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TogbW-00043D-HB for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TogbW-000431-9c for qemu-devel@nongnu.org; Fri, 28 Dec 2012 15:32:30 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBSKWTer007806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Dec 2012 15:32:29 -0500 Received: from blackpad.lan.raisama.net (vpn1-6-233.gru2.redhat.com [10.97.6.233]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBSKWTWE002662; Fri, 28 Dec 2012 15:32:29 -0500 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id C9EA5203D0F; Fri, 28 Dec 2012 18:34:07 -0200 (BRST) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 28 Dec 2012 18:33:59 -0200 Message-Id: <1356726846-10637-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1356726846-10637-1-git-send-email-ehabkost@redhat.com> References: <1356726846-10637-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Igor Mammedov , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 2/9] target-i386: Make cpu_x86_create() get Error argument X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Instead of forcing the caller to guess what went wrong while creating the CPU object, return error information in a Error argument. Also, as cpu_x86_create() won't print error messages itself anymore, change cpu_x86_init() to print any error returned by cpu_x86_create() or cpu_x86_realize(). Signed-off-by: Eduardo Habkost --- Changes v2: - Fix include "qemu-error.h" to use the new "qemu/error-report.h" - Remove bogus error_free() call just after error_propagate() --- target-i386/cpu.c | 5 ++--- target-i386/cpu.h | 2 +- target-i386/helper.c | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 8c4be8b..8c4aecb 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1485,7 +1485,7 @@ static void filter_features_for_kvm(X86CPU *cpu) /* Create and initialize a X86CPU object, based on the full CPU model string * (that may include "+feature,-feature,feature=xxx,feature" feature strings) */ -X86CPU *cpu_x86_create(const char *cpu_model) +X86CPU *cpu_x86_create(const char *cpu_model, Error **errp) { X86CPU *cpu = NULL; CPUX86State *env; @@ -1532,8 +1532,7 @@ out: QDECREF(props); g_strfreev(model_pieces); if (error) { - fprintf(stderr, "%s\n", error_get_pretty(error)); - error_free(error); + error_propagate(errp, error); if (cpu) { object_delete(OBJECT(cpu)); } diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 21b3233..2b45c09 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -979,7 +979,7 @@ int cpu_x86_signal_handler(int host_signum, void *pinfo, void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); -X86CPU *cpu_x86_create(const char *cpu_model); +X86CPU *cpu_x86_create(const char *cpu_model, Error **errp); void cpu_clear_apic_feature(CPUX86State *env); void host_cpuid(uint32_t function, uint32_t count, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx); diff --git a/target-i386/helper.c b/target-i386/helper.c index 7482c97..8b6b4da 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -23,6 +23,7 @@ #include "sysemu/sysemu.h" #include "monitor/monitor.h" #endif +#include "qemu/error-report.h" //#define DEBUG_MMU @@ -1239,21 +1240,27 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector, X86CPU *cpu_x86_init(const char *cpu_model) { - X86CPU *cpu; + X86CPU *cpu = NULL; Error *error = NULL; - cpu = cpu_x86_create(cpu_model); - if (!cpu) { - return NULL; + cpu = cpu_x86_create(cpu_model, &error); + if (error) { + goto error; } x86_cpu_realize(OBJECT(cpu), &error); if (error) { - error_free(error); - object_delete(OBJECT(cpu)); - return NULL; + goto error; } return cpu; + +error: + if (cpu) { + object_delete(OBJECT(cpu)); + } + error_report("%s", error_get_pretty(error)); + error_free(error); + return NULL; } #if !defined(CONFIG_USER_ONLY)