diff mbox series

[4/4] spapr: Make spapr_cpu_core_unrealize() idempotent

Message ID 160251600753.796881.11787439223917154767.stgit@bahia.lan
State New
Headers show
Series spapr: Fix and cleanups for sPAPR CPU core | expand

Commit Message

Greg Kurz Oct. 12, 2020, 3:20 p.m. UTC
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(-)

Comments

Greg Kurz Oct. 12, 2020, 8:24 p.m. UTC | #1
On Mon, 12 Oct 2020 17:20:07 +0200
Greg Kurz <groug@kaod.org> wrote:

> 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>

> ---


Hmmm... this one need some more care because spapr_unrealize_vcpu()
because isn't idempotent. Please ignore it.

>  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[] = {

> 

> 

>
diff mbox series

Patch

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[] = {