From patchwork Fri Jan 11 02:10:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 211186 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 45E272C00D7 for ; Fri, 11 Jan 2013 13:12:37 +1100 (EST) Received: from localhost ([::1]:51194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtU6l-0005CY-8w for incoming@patchwork.ozlabs.org; Thu, 10 Jan 2013 21:12:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtU6V-000548-DS for qemu-devel@nongnu.org; Thu, 10 Jan 2013 21:12:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TtU6R-0000VL-Ug for qemu-devel@nongnu.org; Thu, 10 Jan 2013 21:12:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TtU6R-0000VF-Ly for qemu-devel@nongnu.org; Thu, 10 Jan 2013 21:12:15 -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 r0B2CFs6003735 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Jan 2013 21:12:15 -0500 Received: from dell-pet610-01.lab.eng.brq.redhat.com (dell-pet610-01.lab.eng.brq.redhat.com [10.34.42.20]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0B2CAdu021266; Thu, 10 Jan 2013 21:12:14 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 11 Jan 2013 03:10:16 +0100 Message-Id: <1357870231-26762-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1357870231-26762-1-git-send-email-imammedo@redhat.com> References: <1357870231-26762-1-git-send-email-imammedo@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: ehabkost@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 02/17] target-i386: cpu_x86_register() consolidate freeing resources 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 freeing resources in one place would require setting 'error' to not NULL, so add some more error reporting before jumping to exit branch. Signed-off-by: Igor Mammedov Reviewed-by: Eduardo Habkost Reviewed-by: Eduardo Habkost --- v4: - rebased with "target-i386: move out CPU features initialization in separate func" dropped v3: - set error if cpu_model is empty v2: - add missing 'return -1' on exit if error is not NULL, Spotted-By: Eduardo Habkost --- target-i386/cpu.c | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 0f7a5eb..ea68bc0 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1594,20 +1594,23 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) model_pieces = g_strsplit(cpu_model, ",", 2); if (!model_pieces[0]) { - goto error; + error_setg(&error, "Invalid/empty CPU model name"); + goto out; } name = model_pieces[0]; features = model_pieces[1]; if (cpu_x86_find_by_name(def, name) < 0) { - goto error; + error_setg(&error, "Unable to find CPU definition: %s", name); + goto out; } def->kvm_features |= kvm_default_features; def->ext_features |= CPUID_EXT_HYPERVISOR; if (cpu_x86_parse_featurestr(def, features) < 0) { - goto error; + error_setg(&error, "Invalid cpu_model string format: %s", cpu_model); + goto out; } assert(def->vendor1); env->cpuid_vendor1 = def->vendor1; @@ -1632,17 +1635,15 @@ int cpu_x86_register(X86CPU *cpu, const char *cpu_model) "tsc-frequency", &error); object_property_set_str(OBJECT(cpu), def->model_id, "model-id", &error); + +out: + g_strfreev(model_pieces); if (error) { fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); - goto error; + return -1; } - - g_strfreev(model_pieces); return 0; -error: - g_strfreev(model_pieces); - return -1; } #if !defined(CONFIG_USER_ONLY)