@@ -153,7 +153,7 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
assert(cpu_oc);
for (n = 0; n < EXYNOS4210_NCPUS; n++) {
- Object *cpuobj = object_new(object_class_get_name(cpu_oc));
+ Object *cpuobj = object_new_with_class(cpu_oc);
/* By default A9 CPUs have EL3 enabled. This board does not currently
* support EL3 so the CPU EL3 property is disabled before realization.
@@ -248,7 +248,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)
Object *cpuobj;
ARMCPU *cpu;
- cpuobj = object_new(object_class_get_name(oc));
+ cpuobj = object_new_with_class(oc);
cpu = ARM_CPU(cpuobj);
object_property_set_int(cpuobj, QEMU_PSCI_CONDUIT_SMC,
@@ -555,7 +555,7 @@ static void integratorcp_init(MachineState *machine)
exit(1);
}
- cpuobj = object_new(object_class_get_name(cpu_oc));
+ cpuobj = object_new_with_class(cpu_oc);
/* By default ARM1176 CPUs have EL3 enabled. This board does not
* currently support EL3 so the CPU EL3 property is disabled before
@@ -103,7 +103,7 @@ static void realview_init(MachineState *machine,
}
for (n = 0; n < smp_cpus; n++) {
- Object *cpuobj = object_new(object_class_get_name(cpu_oc));
+ Object *cpuobj = object_new_with_class(cpu_oc);
/* By default A9,A15 and ARM1176 CPUs have EL3 enabled. This board
* does not currently support EL3 so the CPU EL3 property is disabled
@@ -208,7 +208,7 @@ static void versatile_init(MachineState *machine, int board_id)
exit(1);
}
- cpuobj = object_new(object_class_get_name(cpu_oc));
+ cpuobj = object_new_with_class(cpu_oc);
/* By default ARM1176 CPUs have EL3 enabled. This board does not
* currently support EL3 so the CPU EL3 property is disabled before
@@ -215,7 +215,7 @@ static void init_cpus(const char *cpu_model, const char *privdev,
/* Create the actual CPUs */
for (n = 0; n < smp_cpus; n++) {
- Object *cpuobj = object_new(object_class_get_name(cpu_oc));
+ Object *cpuobj = object_new_with_class(cpu_oc);
if (!secure) {
object_property_set_bool(cpuobj, false, "has_el3", NULL);
@@ -177,7 +177,7 @@ static void zynq_init(MachineState *machine)
}
cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
- cpu = ARM_CPU(object_new(object_class_get_name(cpu_oc)));
+ cpu = ARM_CPU(object_new_with_class(cpu_oc));
/* By default A9 CPUs have EL3 enabled. This board does not
* currently support EL3 so the CPU EL3 property is disabled before
@@ -73,7 +73,7 @@ CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
goto out;
}
- cpu = CPU(object_new(object_class_get_name(oc)));
+ cpu = CPU(object_new_with_class(oc));
object_property_set_bool(OBJECT(cpu), true, "realized", &err);
out:
new file mode 100644
@@ -0,0 +1,5 @@
+@@
+expression x;
+@@
+- object_new(object_class_get_name(x))
++ object_new_with_class(x)
@@ -162,7 +162,7 @@ AlphaCPU *cpu_alpha_init(const char *cpu_model)
/* Default to ev67; no reason not to emulate insns by default. */
cpu_class = object_class_by_name(TYPE("ev67"));
}
- cpu = ALPHA_CPU(object_new(object_class_get_name(cpu_class)));
+ cpu = ALPHA_CPU(object_new_with_class(cpu_class));
object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
@@ -2866,7 +2866,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp)
APICCommonState *apic;
ObjectClass *apic_class = OBJECT_CLASS(apic_get_class());
- cpu->apic_state = DEVICE(object_new(object_class_get_name(apic_class)));
+ cpu->apic_state = DEVICE(object_new_with_class(apic_class));
object_property_add_child(OBJECT(cpu), "lapic",
OBJECT(cpu->apic_state), &error_abort);
@@ -110,7 +110,7 @@ M68kCPU *cpu_m68k_init(const char *cpu_model)
if (oc == NULL) {
return NULL;
}
- cpu = M68K_CPU(object_new(object_class_get_name(oc)));
+ cpu = M68K_CPU(object_new_with_class(oc));
env = &cpu->env;
register_m68k_insns(env);
@@ -334,7 +334,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
error_setg(errp, "The CPU definition '%s' requires KVM", info->name);
return;
}
- obj = object_new(object_class_get_name(oc));
+ obj = object_new_with_class(oc);
cpu = S390_CPU(obj);
if (!cpu->model) {
@@ -124,7 +124,7 @@ XtensaCPU *cpu_xtensa_init(const char *cpu_model)
return NULL;
}
- cpu = XTENSA_CPU(object_new(object_class_get_name(oc)));
+ cpu = XTENSA_CPU(object_new_with_class(oc));
env = &cpu->env;
xtensa_irq_init(env);
@@ -4076,8 +4076,8 @@ int main(int argc, char **argv, char **envp)
}
#endif
- current_machine = MACHINE(object_new(object_class_get_name(
- OBJECT_CLASS(machine_class))));
+ current_machine = MACHINE(
+ object_new_with_class(OBJECT_CLASS(machine_class)));
if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
exit(0);
}
object_new_with_class(class) does a better job than object_new(object_class_get_name(class)), because object_class_get_name() lost the class->type and object_new() looked it up again from the name. Manually changed vl.c to fit into 80 character line. Signed-off-by: Radim Krčmář <rkrcmar@redhat.com> --- hw/arm/exynos4210.c | 2 +- hw/arm/highbank.c | 2 +- hw/arm/integratorcp.c | 2 +- hw/arm/realview.c | 2 +- hw/arm/versatilepb.c | 2 +- hw/arm/vexpress.c | 2 +- hw/arm/xilinx_zynq.c | 2 +- qom/cpu.c | 2 +- scripts/coccinelle/object_new_with_class.cocci | 5 +++++ target-alpha/cpu.c | 2 +- target-i386/cpu.c | 2 +- target-m68k/helper.c | 2 +- target-s390x/cpu_models.c | 2 +- target-xtensa/helper.c | 2 +- vl.c | 4 ++-- 15 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 scripts/coccinelle/object_new_with_class.cocci