[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/21] target/loongarch: Fix loongarch_cpu_class_by_name
From: |
Richard Henderson |
Subject: |
[PULL 02/21] target/loongarch: Fix loongarch_cpu_class_by_name |
Date: |
Tue, 19 Jul 2022 23:29:41 +0530 |
From: Xiaojuan Yang <yangxiaojuan@loongson.cn>
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 <yangxiaojuan@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
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 <richard.henderson@linaro.org>
---
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)
--
2.34.1
- [PULL 00/21] loongarch patch queue, Richard Henderson, 2022/07/19
- [PULL 01/21] tests/docker/dockerfiles: Add debian-loongarch-cross.docker, Richard Henderson, 2022/07/19
- [PULL 02/21] target/loongarch: Fix loongarch_cpu_class_by_name,
Richard Henderson <=
- [PULL 03/21] hw/intc/loongarch_pch_pic: Fix bugs for update_irq function, Richard Henderson, 2022/07/19
- [PULL 04/21] target/loongarch/cpu: Fix coverity errors about excp_names, Richard Henderson, 2022/07/19
- [PULL 05/21] target/loongarch/tlb_helper: Fix coverity integer overflow error, Richard Henderson, 2022/07/19
- [PULL 06/21] target/loongarch/op_helper: Fix coverity cond_at_most error, Richard Henderson, 2022/07/19
- [PULL 07/21] target/loongarch/cpu: Fix cpucfg default value, Richard Henderson, 2022/07/19
- [PULL 08/21] fpu/softfloat: Add LoongArch specializations for pickNaN*, Richard Henderson, 2022/07/19
- [PULL 09/21] target/loongarch: Fix float_convd/float_convs test failing, Richard Henderson, 2022/07/19
- [PULL 11/21] tests/tcg/loongarch64: Add clo related instructions test, Richard Henderson, 2022/07/19
- [PULL 10/21] tests/tcg/loongarch64: Add float reference files, Richard Henderson, 2022/07/19
- [PULL 12/21] tests/tcg/loongarch64: Add div and mod related instructions test, Richard Henderson, 2022/07/19