From patchwork Fri Jan 5 15:41:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 760156 Delivered-To: patch@linaro.org Received: by 2002:a5d:678d:0:b0:336:6142:bf13 with SMTP id v13csp103294wru; Fri, 5 Jan 2024 07:44:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXakSnYbW+jPR59v6YsOaGjbXASSqOmHPrRzMVANg6NUQlex5X6h55kW2DzO0mZYU8uUHT X-Received: by 2002:a05:6870:2248:b0:204:b89:69e6 with SMTP id j8-20020a056870224800b002040b8969e6mr2569951oaf.106.1704469440453; Fri, 05 Jan 2024 07:44:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704469440; cv=none; d=google.com; s=arc-20160816; b=Gw1stLPCL4+s+xGnKxmz8RgpxDAzELP9z1QsL0gVoRoAiWHroTaz0Cg3JVFdmM1rUt /hKvbbVMQtH1nFPV3LtXL26wcgUZjctWBwEwYdR1gTVZWcdQ2u1Cd8193oKr+MkyqhTC K/RY1PZDJtWNWNxKCYor/U/QWh19qecuFMYeNsZbalL5JHGpYGZSV+2ksrvkMBBaUKyW SI8wWP/0JyZDhO6Z6muc+RcKpylIDEc/KVoBgiECKcLJAhtlw5n4j1NXUlI8yBoKo5wJ 8pBSr/Zzt1Cdxs09NSMkD5drzIDqG4vp1wAl25eGppLYW4TFHpbbnpPPse1u/9IXCBVE 7+sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/gOHeYXZaENDpXVCc7dFmhih0x0gAZTHQNBrKsITHc4=; fh=mp1QisbMzD3WGnBsnTu2VzBtBm6Z6g4we33B+2s0mSY=; b=g3DnPhHYMCdt7wrj6SYHw33Q7tNKYUTFgvu/+oIDhj5/vZLdDaRhZ9P/dN7df5gMmR 6AayvJJG9apQdj05CnQsLlqjJwb9dEjiaYdNdZJ6K5lig/MaStjLbPDX0WKNq/enU/Sc U/j/mtolXXYwk3vXDKGl+YgWSBCQFfQ7njoIZeTVUGqu9SFr9w7V0VbVPMgmN3ac5W9q 3sHUVP7zglO5lZhKJeb/eiMLceAag2eateoTQOAZImgT0OqWobZJWdUGNG1ov99L8S8p erps5cAItE6hrUmBbxxyxs5vuI1n2Z47mMkGMrncNZOyOF2npgcWU0S2iG5FnELGtbhu vyyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y8mQE3h2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e14-20020a05622a110e00b004280329c06bsi1964843qty.118.2024.01.05.07.44.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jan 2024 07:44:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y8mQE3h2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLmMF-0004WV-Mt; Fri, 05 Jan 2024 10:43:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLmMD-0004VC-N4 for qemu-devel@nongnu.org; Fri, 05 Jan 2024 10:43:37 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLmMA-000322-2P for qemu-devel@nongnu.org; Fri, 05 Jan 2024 10:43:37 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40d8e7a50c1so18915465e9.2 for ; Fri, 05 Jan 2024 07:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704469412; x=1705074212; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/gOHeYXZaENDpXVCc7dFmhih0x0gAZTHQNBrKsITHc4=; b=y8mQE3h2tzrsIz9htvdngU0RPnnNiPdLIrqgWqaN6zRO47rzMwoKvm5cUHjzeZaJHc m5Uvixz/uMz3WDg2AGXQMhBOo44yPq+1pIRbfr67y2cRjhPdwm0vrxKoQHHzcY9ygT0p i0XxSCdWtlTrNuPm5b6aJOUzd1Ab6y5XIGpjFBCeDnwHAXEaDBDw8DzUOb59Y4l6d48U TkXCaYnQ8qj+T11tPJqz4hOWQpgjJeeaLIbhkrNzCWYwdgUGMQuFos24M2pKTrnqKGbc i1Eh6AfjOH2Np8HwEz9g74nu/Y8GD1LCg4Dd0LVHhksQ+kCsbQfyss0H4VT8AjwQ2eth kWGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704469412; x=1705074212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/gOHeYXZaENDpXVCc7dFmhih0x0gAZTHQNBrKsITHc4=; b=jsMHQLOT3TEOAcSQDl58CNd1VZgQIPdG9bTLWViJIBMfx0tj9VgdUUyLVvhw6VbkpE nulzU5X1bLaW/9QuCr0/ccdkNvgYMKRL9uU7qHRxK6bCPsrGqeqNEjc8KEBS5MyToCaz sx2Zrp4KaLdUbg+UTFJzV97+0+mKr/UYLZgcz6TXQph7UV/DOe/H/VoXr9BKOwp2N9pV yRdPyvmShPQhFtsDcFI83WzSJqAiULy6VILQxxpq9sDzSHsMjyM0HL5W3XOxsD1VV2kY E/ljow6k/HbZs0XDqkeeToyNl8TrCwAdQeR8L46+tadNQ+nvW7CrzKGjMQrnP9rxH+Fk MxTQ== X-Gm-Message-State: AOJu0YxLNHV1a1XyrRjKRexfnI6DdSr3TcOspChnwGyRNRLpTJD5N2Yl GjGFopDx5BsErpE4xvJIWTaLFjSbHFBtT6+qtypFDgAemzU= X-Received: by 2002:a05:600c:470b:b0:40d:5c50:573 with SMTP id v11-20020a05600c470b00b0040d5c500573mr1142490wmo.213.1704469412529; Fri, 05 Jan 2024 07:43:32 -0800 (PST) Received: from m1x-phil.lan (juv34-h02-176-184-26-1.dsl.sta.abo.bbox.fr. [176.184.26.1]) by smtp.gmail.com with ESMTPSA id i1-20020a05600c354100b0040d8ff79fd8sm1938104wmq.7.2024.01.05.07.43.30 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 Jan 2024 07:43:32 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Gavin Shan , Igor Mammedov , Richard Henderson , Peter Maydell , Michael Rolnik , "Edgar E. Iglesias" , Brian Cain , Song Gao , Laurent Vivier , Stafford Horne , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Bastian Koppelmann , Max Filippov Subject: [PULL 04/71] cpu: Call object_class_dynamic_cast() once in cpu_class_by_name() Date: Fri, 5 Jan 2024 16:41:57 +0100 Message-ID: <20240105154307.21385-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240105154307.21385-1-philmd@linaro.org> References: <20240105154307.21385-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=philmd@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org For all targets, the CPU class returned from CPUClass::class_by_name() and object_class_dynamic_cast(oc, CPU_RESOLVING_TYPE) need to be compatible. Lets apply the check in cpu_class_by_name() for once, instead of having the check in CPUClass::class_by_name() for individual target. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Gavin Shan Reviewed-by: Igor Mammedov Reviewed-by: Richard Henderson Signed-off-by: Gavin Shan Message-ID: <20231114235628.534334-4-gshan@redhat.com> --- hw/core/cpu-common.c | 8 +++++--- target/alpha/cpu.c | 3 --- target/arm/cpu.c | 4 +--- target/avr/cpu.c | 8 +------- target/cris/cpu.c | 4 +--- target/hexagon/cpu.c | 4 +--- target/hppa/cpu.c | 6 +----- target/loongarch/cpu.c | 8 +------- target/m68k/cpu.c | 4 +--- target/openrisc/cpu.c | 4 +--- target/riscv/cpu.c | 4 +--- target/tricore/cpu.c | 4 +--- target/xtensa/cpu.c | 4 +--- 13 files changed, 16 insertions(+), 49 deletions(-) diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 82dae51a55..d0e7bbdf06 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -154,10 +154,12 @@ ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) assert(cc->class_by_name); assert(cpu_model); oc = cc->class_by_name(cpu_model); - if (oc == NULL || object_class_is_abstract(oc)) { - return NULL; + if (object_class_dynamic_cast(oc, typename) && + !object_class_is_abstract(oc)) { + return oc; } - return oc; + + return NULL; } static void cpu_common_parse_features(const char *typename, char *features, diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c index 91fe8ae095..83345c5c7d 100644 --- a/target/alpha/cpu.c +++ b/target/alpha/cpu.c @@ -141,9 +141,6 @@ static ObjectClass *alpha_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(ALPHA_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_ALPHA_CPU)) { - return NULL; - } return oc; } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 650e09b29c..1c8b787482 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2411,9 +2411,7 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_ARM_CPU)) { - return NULL; - } + return oc; } diff --git a/target/avr/cpu.c b/target/avr/cpu.c index 999c010ded..3e478294a6 100644 --- a/target/avr/cpu.c +++ b/target/avr/cpu.c @@ -160,13 +160,7 @@ static Property avr_cpu_properties[] = { static ObjectClass *avr_cpu_class_by_name(const char *cpu_model) { - ObjectClass *oc; - - oc = object_class_by_name(cpu_model); - if (object_class_dynamic_cast(oc, TYPE_AVR_CPU) == NULL) { - oc = NULL; - } - return oc; + return object_class_by_name(cpu_model); } static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/cris/cpu.c b/target/cris/cpu.c index 675b73ac04..a5083a0077 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -95,9 +95,7 @@ static ObjectClass *cris_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(CRIS_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_CRIS_CPU)) { - oc = NULL; - } + return oc; } diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index 9d1ffc3b4b..aa48f5fe89 100644 --- a/target/hexagon/cpu.c +++ b/target/hexagon/cpu.c @@ -63,9 +63,7 @@ static ObjectClass *hexagon_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_HEXAGON_CPU)) { - return NULL; - } + return oc; } diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index e3e7200b1d..1a5fb6c65b 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -160,12 +160,8 @@ static void hppa_cpu_initfn(Object *obj) static ObjectClass *hppa_cpu_class_by_name(const char *cpu_model) { g_autofree char *typename = g_strconcat(cpu_model, "-cpu", NULL); - ObjectClass *oc = object_class_by_name(typename); - if (oc && object_class_dynamic_cast(oc, TYPE_HPPA_CPU)) { - return oc; - } - return NULL; + return object_class_by_name(typename); } static void hppa_cpu_list_entry(gpointer data, gpointer user_data) diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index 07319d6fb9..81f2d8d8ed 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -718,15 +718,9 @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model) g_autofree char *typename = g_strdup_printf(LOONGARCH_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); - if (!oc) { - return NULL; - } } - if (object_class_dynamic_cast(oc, TYPE_LOONGARCH_CPU)) { - return oc; - } - return NULL; + return oc; } void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 43b1bde21c..1421e77c2c 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -111,9 +111,7 @@ static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(M68K_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL) { - return NULL; - } + return oc; } diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index 1173260017..f7d53c592a 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -164,9 +164,7 @@ static ObjectClass *openrisc_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(OPENRISC_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc != NULL && !object_class_dynamic_cast(oc, TYPE_OPENRISC_CPU)) { - return NULL; - } + return oc; } diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 83c7c0cf07..523e9a16ea 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -646,9 +646,7 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) oc = object_class_by_name(typename); g_strfreev(cpuname); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_RISCV_CPU)) { - return NULL; - } + return oc; } diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 034e01c189..8acacdf0c0 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -132,9 +132,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(TRICORE_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU)) { - return NULL; - } + return oc; } diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index e20fe87bf2..93e782a6e0 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -141,9 +141,7 @@ static ObjectClass *xtensa_cpu_class_by_name(const char *cpu_model) typename = g_strdup_printf(XTENSA_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); - if (oc == NULL || !object_class_dynamic_cast(oc, TYPE_XTENSA_CPU)) { - return NULL; - } + return oc; }