From patchwork Tue Feb 2 10:08:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 44275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 93AF9B7D5B for ; Tue, 2 Feb 2010 21:45:55 +1100 (EST) Received: from localhost ([127.0.0.1]:55314 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcGGF-0001aM-MX for incoming@patchwork.ozlabs.org; Tue, 02 Feb 2010 05:45:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NcFgj-0002pQ-Vv for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:54 -0500 Received: from [199.232.76.173] (port=38612 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcFgh-0002nZ-QK for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:51 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NcFge-000707-Pd for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:50 -0500 Received: from mx20.gnu.org ([199.232.41.8]:28902) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NcFgc-0006y0-GQ for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:47 -0500 Received: from tx2ehsobe003.messaging.microsoft.com ([65.55.88.13] helo=TX2EHSOBE005.bigfish.com) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NcFgV-00042H-Vn for qemu-devel@nongnu.org; Tue, 02 Feb 2010 05:08:40 -0500 Received: from mail70-tx2-R.bigfish.com (10.9.14.240) by TX2EHSOBE005.bigfish.com (10.9.40.25) with Microsoft SMTP Server id 8.1.340.0; Tue, 2 Feb 2010 10:08:38 +0000 Received: from mail70-tx2 (localhost [127.0.0.1]) by mail70-tx2-R.bigfish.com (Postfix) with ESMTP id 6E4471850665; Tue, 2 Feb 2010 10:08:38 +0000 (UTC) X-SpamScore: -4 X-BigFish: VPS-4(zzab9bh936eMzz1202hzzz32i6bh66h) Received: from mail70-tx2 (localhost.localdomain [127.0.0.1]) by mail70-tx2 (MessageSwitch) id 1265105316710942_29151; Tue, 2 Feb 2010 10:08:36 +0000 (UTC) Received: from TX2EHSMHS015.bigfish.com (unknown [10.9.14.237]) by mail70-tx2.bigfish.com (Postfix) with ESMTP id 9F410F48012; Tue, 2 Feb 2010 10:08:36 +0000 (UTC) Received: from ausb3extmailp02.amd.com (163.181.251.22) by TX2EHSMHS015.bigfish.com (10.9.99.115) with Microsoft SMTP Server (TLS) id 14.0.482.39; Tue, 2 Feb 2010 10:08:36 +0000 Received: from ausb3twp01.amd.com (ausb3twp01.amd.com [163.181.250.37]) by ausb3extmailp02.amd.com (Switch-3.2.7/Switch-3.2.7) with ESMTP id o12AA9Si002799; Tue, 2 Feb 2010 04:10:17 -0600 X-WSS-ID: 0KX7LHZ-01-GT3-02 X-M-MSG: Received: from sausexbh2.amd.com (SAUSEXBH2.amd.com [163.181.22.102]) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 2DA4C1028756; Tue, 2 Feb 2010 04:08:23 -0600 (CST) Received: from sausexmb1.amd.com ([163.181.3.156]) by sausexbh2.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Feb 2010 04:08:26 -0600 Received: from seurexmb1.amd.com ([165.204.9.130]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Feb 2010 04:08:26 -0600 Received: from gwo.osrc.amd.com ([165.204.16.204]) by seurexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 2 Feb 2010 11:08:19 +0100 Received: from localhost.localdomain (tronje.osrc.amd.com [165.204.15.48]) by gwo.osrc.amd.com (Postfix) with ESMTP id 7ECCC49C1AB; Tue, 2 Feb 2010 10:08:38 +0000 (GMT) From: Andre Przywara To: qemu-devel@nongnu.org Date: Tue, 2 Feb 2010 11:08:12 +0100 Message-ID: <1265105301-3455-5-git-send-email-andre.przywara@amd.com> X-Mailer: git-send-email 1.6.4 In-Reply-To: <1265105301-3455-1-git-send-email-andre.przywara@amd.com> References: <1265105301-3455-1-git-send-email-andre.przywara@amd.com> X-OriginalArrivalTime: 02 Feb 2010 10:08:19.0666 (UTC) FILETIME=[A5250B20:01CAA3EF] MIME-Version: 1.0 X-Reverse-DNS: ausb3extmailp02.amd.com X-detected-operating-system: by mx20.gnu.org: Windows 2000 SP4, XP SP1+ X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: john.cooper@redhat.com, Andre Przywara Subject: [Qemu-devel] [PATCH 04/13] cpuid: Replace strtok with get_opt_name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org To avoid the non-reentrant capable strtok() use the QEMU defined get_opt_name() to parse the -cpu parameter list. Since there is a name clash between linux-user/mmap.c:qemu_malloc() and qemu-malloc.c:qemu_malloc() I copied the small function from qemu-option.c into cpuid.c. Not the best solution, bit IMO the least intrusive and smallest one. Signed-off-by: Andre Przywara --- target-i386/cpuid.c | 34 ++++++++++++++++++++++++---------- 1 files changed, 24 insertions(+), 10 deletions(-) diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c index cc080f4..0238718 100644 --- a/target-i386/cpuid.c +++ b/target-i386/cpuid.c @@ -24,6 +24,23 @@ #include "cpu.h" #include "kvm.h" +static const char *get_opt_name(char *buf, int buf_size, + const char *p, char delim) +{ + char *q; + + q = buf; + while (*p != '\0' && *p != delim) { + if (q && (q - buf) < buf_size - 1) + *q++ = *p; + p++; + } + if (q) + *q = '\0'; + + return p; +} + /* feature flags taken from "Intel Processor Identification and the CPUID * Instruction" and AMD's "CPUID Specification". In cases of disagreement * about feature names, the Linux name is used. */ @@ -423,8 +440,8 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) unsigned int i; x86_def_t *def; - char *s = strdup(cpu_model); - char *featurestr, *name = strtok(s, ","); + const char* s; + char featurestr[64]; uint32_t plus_features = 0, plus_ext_features = 0, plus_ext2_features = 0, plus_ext3_features = 0, plus_kvm_features = 0; uint32_t minus_features = 0, minus_ext_features = 0, @@ -432,14 +449,15 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) minus_kvm_features = 0; uint32_t numvalue; + s = get_opt_name(featurestr, 64, cpu_model, ','); def = NULL; for (i = 0; i < ARRAY_SIZE(x86_defs); i++) { - if (strcmp(name, x86_defs[i].name) == 0) { + if (strcmp(featurestr, x86_defs[i].name) == 0) { def = &x86_defs[i]; break; } } - if (kvm_enabled() && strcmp(name, "host") == 0) { + if (kvm_enabled() && strcmp(featurestr, "host") == 0) { cpu_x86_fill_host(x86_cpu_def); } else if (!def) { goto error; @@ -453,10 +471,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) &plus_ext_features, &plus_ext2_features, &plus_ext3_features, &plus_kvm_features); - featurestr = strtok(NULL, ","); - - while (featurestr) { + while (*s != 0) { char *val; + s = get_opt_name(featurestr, 64, s + 1, ','); if (featurestr[0] == '+') { add_flagname_to_bitmaps(featurestr + 1, &plus_features, &plus_ext_features, &plus_ext2_features, @@ -536,7 +553,6 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) "(+feature|-feature|feature=xyz)\n", featurestr); goto error; } - featurestr = strtok(NULL, ","); } x86_cpu_def->features |= plus_features; x86_cpu_def->ext_features |= plus_ext_features; @@ -548,11 +564,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model) x86_cpu_def->ext2_features &= ~minus_ext2_features; x86_cpu_def->ext3_features &= ~minus_ext3_features; x86_cpu_def->kvm_features &= ~minus_kvm_features; - free(s); return 0; error: - free(s); return -1; }