[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] spapr: Make spapr_cpu_core_unrealize() idempotent
From: |
Greg Kurz |
Subject: |
[PATCH 4/4] spapr: Make spapr_cpu_core_unrealize() idempotent |
Date: |
Mon, 12 Oct 2020 17:20:07 +0200 |
User-agent: |
StGit/0.21 |
spapr_cpu_core_realize() has an err_unrealize label which partially
duplicates the code of spapr_cpu_core_realize().
Let's make spapr_cpu_core_unrealize() idempotent and call it instead.
The registration and unregistration of the reset handler are moved
around to simplify the code even more.
Signed-off-by: Greg Kurz <groug@kaod.org>
---
hw/ppc/spapr_cpu_core.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index cffd74f542ba..e3fd81eb9741 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -227,11 +227,13 @@ static void spapr_cpu_core_unrealize(DeviceState *dev)
CPUCore *cc = CPU_CORE(dev);
int i;
- qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
-
for (i = 0; i < cc->nr_threads; i++) {
- spapr_unrealize_vcpu(sc->threads[i], sc);
+ if (sc->threads[i]) {
+ spapr_unrealize_vcpu(sc->threads[i], sc);
+ }
}
+
+ qemu_unregister_reset(spapr_cpu_core_reset_handler, sc);
}
static bool spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
@@ -326,19 +328,14 @@ static void spapr_cpu_core_realize(DeviceState *dev,
Error **errp)
}
}
+ qemu_register_reset(spapr_cpu_core_reset_handler, sc);
+
for (j = 0; j < cc->nr_threads; j++) {
if (!spapr_realize_vcpu(sc->threads[j], spapr, sc, errp)) {
- goto err_unrealize;
+ spapr_cpu_core_unrealize(dev);
+ return;
}
}
-
- qemu_register_reset(spapr_cpu_core_reset_handler, sc);
- return;
-
-err_unrealize:
- while (--j >= 0) {
- spapr_unrealize_vcpu(sc->threads[j], sc);
- }
}
static Property spapr_cpu_core_properties[] = {