Message ID | 20230907003553.1636896-18-gshan@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Unified CPU type check | expand |
On Thu, Sep 07, 2023 at 10:35:38AM +1000, Gavin Shan wrote: > For target/tricore, the CPU type name is always the combination of the > CPU model name and suffix. The CPU model names have been correctly > shown in tricore_cpu_list_entry(). > > Use generic helper cpu_model_from_type() to show the CPU model names > in the above function. tricore_cpu_class_by_name() is also improved > by merging the condition of '@oc == NULL' to object_class_dynamic_cast(). > > Signed-off-by: Gavin Shan <gshan@redhat.com> > --- > target/tricore/cpu.c | 9 +++++---- > target/tricore/helper.c | 13 +++++-------- > 2 files changed, 10 insertions(+), 12 deletions(-) Reviewed-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de> Cheers, Bastian
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 133a9ac70e..066249e50d 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -140,11 +140,12 @@ 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) || - object_class_is_abstract(oc)) { - return NULL; + if (object_class_dynamic_cast(oc, TYPE_TRICORE_CPU) && + !object_class_is_abstract(oc)) { + return oc; } - return oc; + + return NULL; } static void tc1796_initfn(Object *obj) diff --git a/target/tricore/helper.c b/target/tricore/helper.c index 6d076ac36f..21f4e1f1a3 100644 --- a/target/tricore/helper.c +++ b/target/tricore/helper.c @@ -98,14 +98,11 @@ bool tricore_cpu_tlb_fill(CPUState *cs, vaddr address, int size, static void tricore_cpu_list_entry(gpointer data, gpointer user_data) { - ObjectClass *oc = data; - const char *typename; - char *name; - - typename = object_class_get_name(oc); - name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_TRICORE_CPU)); - qemu_printf(" %s\n", name); - g_free(name); + const char *typename = object_class_get_name(OBJECT_CLASS(data)); + char *model = cpu_model_from_type(typename); + + qemu_printf(" %s\n", model); + g_free(model); } void tricore_cpu_list(void)
For target/tricore, the CPU type name is always the combination of the CPU model name and suffix. The CPU model names have been correctly shown in tricore_cpu_list_entry(). Use generic helper cpu_model_from_type() to show the CPU model names in the above function. tricore_cpu_class_by_name() is also improved by merging the condition of '@oc == NULL' to object_class_dynamic_cast(). Signed-off-by: Gavin Shan <gshan@redhat.com> --- target/tricore/cpu.c | 9 +++++---- target/tricore/helper.c | 13 +++++-------- 2 files changed, 10 insertions(+), 12 deletions(-)