From nobody Sun Nov 2 11:51:55 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509115395552449.98307216424666; Fri, 27 Oct 2017 07:43:15 -0700 (PDT) Received: from localhost ([::1]:57637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e85qd-00021F-KN for importer@patchew.org; Fri, 27 Oct 2017 10:42:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e85X0-0006HM-Hx for qemu-devel@nongnu.org; Fri, 27 Oct 2017 10:22:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e85Wz-00019F-9k for qemu-devel@nongnu.org; Fri, 27 Oct 2017 10:22:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e85Wz-00017V-0B for qemu-devel@nongnu.org; Fri, 27 Oct 2017 10:22:41 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2027E21A2; Fri, 27 Oct 2017 14:22:40 +0000 (UTC) Received: from localhost (ovpn-116-67.gru2.redhat.com [10.97.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 155E95D751; Fri, 27 Oct 2017 14:22:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2027E21A2 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: Peter Maydell Date: Fri, 27 Oct 2017 16:20:47 +0200 Message-Id: <20171027142107.15542-20-ehabkost@redhat.com> In-Reply-To: <20171027142107.15542-1-ehabkost@redhat.com> References: <20171027142107.15542-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 27 Oct 2017 14:22:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL v2 19/39] sh4: simplify superh_cpu_class_by_name() 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: Igor Mammedov , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Igor Mammedov currently for sh4 cpu_model argument for '-cpu' option could be either 'cpu model' name or cpu_typename. however typically '-cpu' takes 'cpu model' name and cpu type for sh4 target isn't advertised publicly ('-cpu help' prints only 'cpu model' names) so we shouldn't care about this use case (it's more of a bug). 1. Drop '-cpu cpu_typename' to align with the rest of targets. 2. Compose searched for typename from cpu model and use it with object_class_by_name() directly instead of over-complicated object_class_get_list() g_slist_find_custom() + superh_cpu_name_compare() With #1 droped, #2 could be used for both lookups which simplifies superh_cpu_class_by_name() quite a bit. Signed-off-by: Igor Mammedov Acked-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <1507211474-188400-23-git-send-email-imammedo@redhat.com> [ehabkost: Include fixup sent by Igor] Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Eduardo Habkost --- linux-user/main.c | 2 +- target/sh4/cpu.c | 34 ++++++++++++---------------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/linux-user/main.c b/linux-user/main.c index 28353f1a75..aa02f25b85 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -4331,7 +4331,7 @@ int main(int argc, char **argv, char **envp) cpu_model =3D "750"; # endif #elif defined TARGET_SH4 - cpu_model =3D TYPE_SH7785_CPU; + cpu_model =3D "sh7785"; #elif defined TARGET_S390X cpu_model =3D "qemu"; #else diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c index ec6db61bdf..972c809d8c 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -120,36 +120,26 @@ void sh4_cpu_list(FILE *f, fprintf_function cpu_fprin= tf) g_slist_free(list); } =20 -static gint superh_cpu_name_compare(gconstpointer a, gconstpointer b) -{ - const SuperHCPUClass *scc =3D SUPERH_CPU_CLASS(a); - const char *name =3D b; - - return strcasecmp(scc->name, name); -} - static ObjectClass *superh_cpu_class_by_name(const char *cpu_model) { ObjectClass *oc; - GSList *list, *item; + char *s, *typename =3D NULL; =20 - if (strcasecmp(cpu_model, "any") =3D=3D 0) { - return object_class_by_name(TYPE_SH7750R_CPU); + s =3D g_ascii_strdown(cpu_model, -1); + if (strcmp(s, "any") =3D=3D 0) { + oc =3D object_class_by_name(TYPE_SH7750R_CPU); + goto out; } =20 - oc =3D object_class_by_name(cpu_model); - if (oc !=3D NULL && object_class_dynamic_cast(oc, TYPE_SUPERH_CPU) != =3D NULL - && !object_class_is_abstract(oc)) { - return oc; + typename =3D g_strdup_printf(SUPERH_CPU_TYPE_NAME("%s"), s); + oc =3D object_class_by_name(typename); + if (oc !=3D NULL && object_class_is_abstract(oc)) { + oc =3D NULL; } =20 - oc =3D NULL; - list =3D object_class_get_list(TYPE_SUPERH_CPU, false); - item =3D g_slist_find_custom(list, cpu_model, superh_cpu_name_compare); - if (item !=3D NULL) { - oc =3D item->data; - } - g_slist_free(list); +out: + g_free(s); + g_free(typename); return oc; } =20 --=20 2.13.6