From nobody Sun Feb 8 22:49:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504099884665798.4967787718424; Wed, 30 Aug 2017 06:31:24 -0700 (PDT) Received: from localhost ([::1]:50600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn35W-0007J2-Lm for importer@patchew.org; Wed, 30 Aug 2017 09:31:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn2z9-0001ow-TK for qemu-devel@nongnu.org; Wed, 30 Aug 2017 09:24:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn2z8-0003Yw-Up for qemu-devel@nongnu.org; Wed, 30 Aug 2017 09:24:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn2z8-0003YG-PQ; Wed, 30 Aug 2017 09:24:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C609C404302; Wed, 30 Aug 2017 13:24:45 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id C67FF77DEE; Wed, 30 Aug 2017 13:24:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C609C404302 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=imammedo@redhat.com From: Igor Mammedov To: qemu-devel@nongnu.org Date: Wed, 30 Aug 2017 15:24:33 +0200 Message-Id: <1504099475-241036-7-git-send-email-imammedo@redhat.com> In-Reply-To: <1504099475-241036-1-git-send-email-imammedo@redhat.com> References: <1504099475-241036-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 30 Aug 2017 13:24:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 6/8] ppc: simplify cpu model lookup by PVR X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-ppc@nongnu.org, Alexander Graf , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Igor Mammedov --- v2: - if going PVR lookup routem check that cpu_model string consumed completely, as PVR number shouldn't have any stray symbol in it. --- target/ppc/translate_init.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c index cf0d795..a803a7f 100644 --- a/target/ppc/translate_init.c +++ b/target/ppc/translate_init.c @@ -34,6 +34,7 @@ #include "hw/ppc/ppc.h" #include "mmu-book3s-v3.h" #include "sysemu/qtest.h" +#include "qemu/cutils.h" =20 //#define PPC_DUMP_CPU //#define PPC_DEBUG_SPR @@ -10203,22 +10204,16 @@ static ObjectClass *ppc_cpu_class_by_name(const c= har *name) char *cpu_model, *typename; ObjectClass *oc; const char *p; - int i, len; - - /* Check if the given name is a PVR */ - len =3D strlen(name); - if (len =3D=3D 10 && name[0] =3D=3D '0' && name[1] =3D=3D 'x') { - p =3D name + 2; - goto check_pvr; - } else if (len =3D=3D 8) { - p =3D name; - check_pvr: - for (i =3D 0; i < 8; i++) { - if (!qemu_isxdigit(*p++)) - break; - } - if (i =3D=3D 8) { - return OBJECT_CLASS(ppc_cpu_class_by_pvr(strtoul(name, NULL, 1= 6))); + unsigned long pvr; + + /* Lookup by PVR if cpu_model is valid 8 digit hex number + * (excl: 0x prefix if present) + */ + if (!qemu_strtoul(name, &p, 16, &pvr)) { + int len =3D p - name; + len =3D (len =3D=3D 10) && (name[1] =3D=3D 'x') ? len - 2 : len; + if ((len =3D=3D 8) && (*p =3D=3D '\0')) { + return OBJECT_CLASS(ppc_cpu_class_by_pvr(pvr)); } } =20 --=20 2.7.4