@@ -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,
@@ -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;
}
@@ -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;
}
@@ -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)
@@ -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;
}
@@ -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;
}
@@ -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)
@@ -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)
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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;
}