From patchwork Tue Jul 19 17:59:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 591660 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4206793max; Tue, 19 Jul 2022 11:01:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uTWUXzRbraMdfa7/irIG9VZD0uzBQIWGbf+QHGN6iuogHi95voR4GFhk2cIuRXsKiRUl07 X-Received: by 2002:ac8:130c:0:b0:31e:ed4b:2d25 with SMTP id e12-20020ac8130c000000b0031eed4b2d25mr8859917qtj.497.1658253698632; Tue, 19 Jul 2022 11:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658253698; cv=none; d=google.com; s=arc-20160816; b=xsr7zVfxJfynmAFq+umm1HcTercJpbb/VCnXjGM0ZuRHhsrwEhSPxrluLOx1z2kT2J A5KIQlLLhR4nuLKm532kZVmWSG5owpk16xn501KkDIDcP9wNAjevnp/erbJDvZQzvkkJ +yOhZhQ+OZTu7Iea1vQ/vTX/ZRyYM7B56wMWGrnNRBgfgToMJihO+4ixs9farFoIV517 gWh5+u9+sv8Uhd1k1Mh/QXC5i+dT/sUGoLcLPpI3VMmVeTHd/4m1i22U7pzNNcur7Dbs Cj9YbIXBlsaXJ0UOnsPp7iDbU1pTF5/gTsgbcsPjX3DPjS1tYXfmY1h3NVuO11mxQdTG tNyg== 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=G84KLuP+strtKf2lZiqlyTltP5yjUze9lKDptIZ/K4c=; b=OcjrueqG1bnTCOazFZd5pbErFR40DYpzQVWmv/7Lk84RimBPjTtpbvrD29x+05y+0d LI1om0ugAPakDJrPmPEoqncFuw5c0G1uZEgNMuMINGQC/nUfoL6rQe2MmsNMhnU4PmCj nkZu9hKK82KE2TsJm51oP2pBsLg3xrnAWwoBbDkaaLP09ZgUGNlSdb8zZTIBGutvYG5s YuLcA3wnEeg6iD93mtlconKsfMtGRMAdDD1zJwAD3Vp1JRJHrYQITWRt4YkJW93ylzAc njDmDOi9QRtazh+3P1kBA1la9mxcjFAl6ryNYkCFxHX/u3txHR4/VmGRSnhzj4ugQncw fujw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vKUmUIOH; 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 q40-20020a05620a2a6800b006b2527f208dsi7745823qkp.2.2022.07.19.11.01.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Jul 2022 11:01:38 -0700 (PDT) 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=vKUmUIOH; 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]:52206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDrXO-0005q9-7D for patch@linaro.org; Tue, 19 Jul 2022 14:01:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDrW8-0005nk-Iq for qemu-devel@nongnu.org; Tue, 19 Jul 2022 14:00:20 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]:41788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDrW6-0006AB-UF for qemu-devel@nongnu.org; Tue, 19 Jul 2022 14:00:20 -0400 Received: by mail-ot1-x332.google.com with SMTP id w6-20020a056830410600b0061c99652493so7068130ott.8 for ; Tue, 19 Jul 2022 11:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G84KLuP+strtKf2lZiqlyTltP5yjUze9lKDptIZ/K4c=; b=vKUmUIOHfqV/G4OEq2ih4MZVNeHeOlczU2RdHcy5qo7QtcOsMZiGhytB+aEciPO5Zp Ldlouv1t9BN7iPWLVMXmpKzvWIJLFj5qjeyyfIxCC87N7OTZ+GkOA0cjkLc4y0sdZGTA Zwgo/cKP/8Md6OUh8edD6w/iQ4kHw8gANiGURQUOFdRgZZTqhdzrqy3BjTWKVcTix1fh 7fupQx+dlZGLJGDJ1NqlORKc3LfiS4b6z7IH9xQo8Z4Q36Ni2z4UNH0DG/vhQpPS/41/ QVYND4XapTQpsa3jJFRrYywnbWuO6P7iL3ptbot3r4ccWFA6mbreOXkMNyGhN4ZOEJvT QR1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G84KLuP+strtKf2lZiqlyTltP5yjUze9lKDptIZ/K4c=; b=CXZ5dLfAEk+QtDCqAeEGPn74NGwz/hXqRhPrr9Al/Gk2Yr32ZukfFdh0n5wDmAC6ge 7Z32/XhmoetYcHVrTwKPbTmyVLDPYgvgfATAcuQTHl4iFNshb5q2a+l9hiTbFgZCbS3L uyJLAEG54fsIaRbsWDvtK32NaWPmZ1+64oba4blklhX6WgsQok3XaO0JkiVMyFsvy3Aq p6REjb47Ht8zUfLGj9449cVJyGXL1PoJYuWZPncSADNGmh8v50BLeZ2UXrekKCq3f1rf IOwabF0Nsv9TAUwlpDAzTpemycIU3LtuEZ6R8dSvFK8n6h19U0S3y9c/ydBx5iL0Ycfw XuZA== X-Gm-Message-State: AJIora9Y+XOqJmfyQvztefQtOqxJkx/w5BRgqnuo3gvymcbr27Hmj05m IC8BcBerOVr6ChGhSJDx9/bxjxzoTuL960Mb X-Received: by 2002:a05:6830:2b28:b0:61c:74e0:4d8a with SMTP id l40-20020a0568302b2800b0061c74e04d8amr12974318otv.329.1658253617478; Tue, 19 Jul 2022 11:00:17 -0700 (PDT) Received: from stoup.. ([172.58.110.182]) by smtp.gmail.com with ESMTPSA id c25-20020a4ae259000000b0035eb4e5a6cesm6286747oot.36.2022.07.19.11.00.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Jul 2022 11:00:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Xiaojuan Yang Subject: [PULL 02/21] target/loongarch: Fix loongarch_cpu_class_by_name Date: Tue, 19 Jul 2022 23:29:41 +0530 Message-Id: <20220719180000.378186-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220719180000.378186-1-richard.henderson@linaro.org> References: <20220719180000.378186-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::332; envelope-from=richard.henderson@linaro.org; helo=mail-ot1-x332.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=ham 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" From: Xiaojuan Yang The cpu_model argument may already have the '-loongarch-cpu' suffix, e.g. when using the default for the LS7A1000 machine. If that fails, try again with the suffix. Validate that the object created by the function is derived from the proper base class. Signed-off-by: Xiaojuan Yang Reviewed-by: Richard Henderson Message-Id: <20220715060740.1500628-2-yangxiaojuan@loongson.cn> [rth: Try without and then with the suffix, to avoid testsuite breakage.] Signed-off-by: Richard Henderson --- target/loongarch/cpu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c index e21715592a..5573468a7d 100644 --- a/target/loongarch/cpu.c +++ b/target/loongarch/cpu.c @@ -571,12 +571,22 @@ static void loongarch_cpu_init(Object *obj) static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model) { ObjectClass *oc; - char *typename; - typename = g_strdup_printf(LOONGARCH_CPU_TYPE_NAME("%s"), cpu_model); - oc = object_class_by_name(typename); - g_free(typename); - return oc; + oc = object_class_by_name(cpu_model); + if (!oc) { + 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) + && !object_class_is_abstract(oc)) { + return oc; + } + return NULL; } void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)