diff mbox series

[1/5] hw/nmi: Have nmi_monitor_handler() return a boolean indicating error

Message ID 20230216122524.67212-2-philmd@linaro.org
State New
Headers show
Series bulk: Have object_child_foreach() take Error* and return boolean | expand

Commit Message

Philippe Mathieu-Daudé Feb. 16, 2023, 12:25 p.m. UTC
Following the example documented since commit e3fe3988d7 ("error:
Document Error API usage rules"), have the nmi_monitor_handler
return a boolean indicating whether an error is set or not and
convert its implementations.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/nmi.c              | 3 +--
 hw/hppa/machine.c          | 3 ++-
 hw/i386/x86.c              | 3 ++-
 hw/intc/m68k_irqc.c        | 4 +++-
 hw/m68k/q800.c             | 4 +++-
 hw/misc/macio/gpio.c       | 4 +++-
 hw/ppc/pnv.c               | 3 ++-
 hw/ppc/spapr.c             | 3 ++-
 hw/s390x/s390-virtio-ccw.c | 4 +++-
 include/hw/nmi.h           | 3 ++-
 10 files changed, 23 insertions(+), 11 deletions(-)

Comments

Markus Armbruster Feb. 23, 2023, 3:26 p.m. UTC | #1
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Following the example documented since commit e3fe3988d7 ("error:
> Document Error API usage rules"), have the nmi_monitor_handler
> return a boolean indicating whether an error is set or not and
> convert its implementations.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/core/nmi.c              | 3 +--
>  hw/hppa/machine.c          | 3 ++-
>  hw/i386/x86.c              | 3 ++-
>  hw/intc/m68k_irqc.c        | 4 +++-
>  hw/m68k/q800.c             | 4 +++-
>  hw/misc/macio/gpio.c       | 4 +++-
>  hw/ppc/pnv.c               | 3 ++-
>  hw/ppc/spapr.c             | 3 ++-
>  hw/s390x/s390-virtio-ccw.c | 4 +++-
>  include/hw/nmi.h           | 3 ++-
>  10 files changed, 23 insertions(+), 11 deletions(-)
>
> diff --git a/hw/core/nmi.c b/hw/core/nmi.c
> index 481c4b3c7e..76cb3ba3b0 100644
> --- a/hw/core/nmi.c
> +++ b/hw/core/nmi.c
> @@ -43,8 +43,7 @@ static int do_nmi(Object *o, void *opaque)
>          NMIClass *nc = NMI_GET_CLASS(n);
>  
>          ns->handled = true;
> -        nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
> -        if (ns->err) {
> +        if (!nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err)) {
>              return -1;
>          }
>      }
> diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
> index 7ac68c943f..da7c36c554 100644
> --- a/hw/hppa/machine.c
> +++ b/hw/hppa/machine.c
> @@ -437,13 +437,14 @@ static void hppa_machine_reset(MachineState *ms, ShutdownCause reason)
>      cpu[0]->env.gr[19] = FW_CFG_IO_BASE;
>  }
>  
> -static void hppa_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool hppa_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs;
>  
>      CPU_FOREACH(cs) {
>          cpu_interrupt(cs, CPU_INTERRUPT_NMI);
>      }
> +    return true;
>  }
>  
>  static void hppa_machine_init_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index eaff4227bd..8bd0691705 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -501,7 +501,7 @@ const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
>      return ms->possible_cpus;
>  }
>  
> -static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool x86_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      /* cpu index isn't used */
>      CPUState *cs;
> @@ -515,6 +515,7 @@ static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
>              apic_deliver_nmi(cpu->apic_state);
>          }
>      }
> +    return true;
>  }
>  
>  static long get_file_size(FILE *f)
> diff --git a/hw/intc/m68k_irqc.c b/hw/intc/m68k_irqc.c
> index 0c515e4ecb..e05083e756 100644
> --- a/hw/intc/m68k_irqc.c
> +++ b/hw/intc/m68k_irqc.c
> @@ -70,9 +70,11 @@ static void m68k_irqc_instance_init(Object *obj)
>      qdev_init_gpio_in(DEVICE(obj), m68k_set_irq, M68K_IRQC_LEVEL_NUM);
>  }
>  
> -static void m68k_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool m68k_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      m68k_set_irq(n, M68K_IRQC_LEVEL_7, 1);
> +
> +    return true;
>  }
>  
>  static const VMStateDescription vmstate_m68k_irqc = {
> diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
> index 9d52ca6613..8631a226cd 100644
> --- a/hw/m68k/q800.c
> +++ b/hw/m68k/q800.c
> @@ -227,13 +227,15 @@ static void glue_auxmode_set_irq(void *opaque, int irq, int level)
>      s->auxmode = level;
>  }
>  
> -static void glue_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool glue_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      GLUEState *s = GLUE(n);
>  
>      /* Hold NMI active for 100ms */
>      GLUE_set_irq(s, GLUE_IRQ_IN_NMI, 1);
>      timer_mod(s->nmi_release, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 100);
> +
> +    return true;
>  }
>  
>  static void glue_nmi_release(void *opaque)
> diff --git a/hw/misc/macio/gpio.c b/hw/misc/macio/gpio.c
> index c8ac5633b2..0a7214421c 100644
> --- a/hw/misc/macio/gpio.c
> +++ b/hw/misc/macio/gpio.c
> @@ -182,10 +182,12 @@ static void macio_gpio_reset(DeviceState *dev)
>      macio_set_gpio(s, 1, true);
>  }
>  
> -static void macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      macio_set_gpio(MACIO_GPIO(n), 9, true);
>      macio_set_gpio(MACIO_GPIO(n), 9, false);
> +
> +    return true;
>  }
>  
>  static void macio_gpio_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
> index 44b1fbbc93..38e69f3b39 100644
> --- a/hw/ppc/pnv.c
> +++ b/hw/ppc/pnv.c
> @@ -2309,13 +2309,14 @@ static void pnv_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg)
>      }
>  }
>  
> -static void pnv_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool pnv_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs;
>  
>      CPU_FOREACH(cs) {
>          async_run_on_cpu(cs, pnv_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL);
>      }
> +    return true;
>  }
>  
>  static void pnv_machine_class_init(ObjectClass *oc, void *data)
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 4921198b9d..d298068169 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -3464,13 +3464,14 @@ void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg)
>      }
>  }
>  
> -static void spapr_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool spapr_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs;
>  
>      CPU_FOREACH(cs) {
>          async_run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
>      }
> +    return true;
>  }
>  
>  int spapr_lmb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index f22f61b8b6..af7e6c632a 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -570,11 +570,13 @@ static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
>      return NULL;
>  }
>  
> -static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
> +static bool s390_nmi(NMIState *n, int cpu_index, Error **errp)
>  {
>      CPUState *cs = qemu_get_cpu(cpu_index);
>  
>      s390_cpu_restart(S390_CPU(cs));
> +
> +    return true;
>  }
>  
>  static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
> diff --git a/include/hw/nmi.h b/include/hw/nmi.h
> index fff41bebc6..3e827a254a 100644
> --- a/include/hw/nmi.h
> +++ b/include/hw/nmi.h
> @@ -37,7 +37,8 @@ typedef struct NMIState NMIState;
>  struct NMIClass {
>      InterfaceClass parent_class;
>  
> -    void (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
> +    /** Returns: %true on success, %false on error. */
> +    bool (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
>  };
>  
>  void nmi_monitor_handle(int cpu_index, Error **errp);

None of the handlers can actually fail.  Evidence: you add only return
true, never return false.  Correct (I checked).

I think I'd make it official and drop the handler's Error ** parameter
instead of changing its return type.

You decide.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox series

Patch

diff --git a/hw/core/nmi.c b/hw/core/nmi.c
index 481c4b3c7e..76cb3ba3b0 100644
--- a/hw/core/nmi.c
+++ b/hw/core/nmi.c
@@ -43,8 +43,7 @@  static int do_nmi(Object *o, void *opaque)
         NMIClass *nc = NMI_GET_CLASS(n);
 
         ns->handled = true;
-        nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err);
-        if (ns->err) {
+        if (!nc->nmi_monitor_handler(n, ns->cpu_index, &ns->err)) {
             return -1;
         }
     }
diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index 7ac68c943f..da7c36c554 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -437,13 +437,14 @@  static void hppa_machine_reset(MachineState *ms, ShutdownCause reason)
     cpu[0]->env.gr[19] = FW_CFG_IO_BASE;
 }
 
-static void hppa_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool hppa_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     CPUState *cs;
 
     CPU_FOREACH(cs) {
         cpu_interrupt(cs, CPU_INTERRUPT_NMI);
     }
+    return true;
 }
 
 static void hppa_machine_init_class_init(ObjectClass *oc, void *data)
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index eaff4227bd..8bd0691705 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -501,7 +501,7 @@  const CPUArchIdList *x86_possible_cpu_arch_ids(MachineState *ms)
     return ms->possible_cpus;
 }
 
-static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool x86_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     /* cpu index isn't used */
     CPUState *cs;
@@ -515,6 +515,7 @@  static void x86_nmi(NMIState *n, int cpu_index, Error **errp)
             apic_deliver_nmi(cpu->apic_state);
         }
     }
+    return true;
 }
 
 static long get_file_size(FILE *f)
diff --git a/hw/intc/m68k_irqc.c b/hw/intc/m68k_irqc.c
index 0c515e4ecb..e05083e756 100644
--- a/hw/intc/m68k_irqc.c
+++ b/hw/intc/m68k_irqc.c
@@ -70,9 +70,11 @@  static void m68k_irqc_instance_init(Object *obj)
     qdev_init_gpio_in(DEVICE(obj), m68k_set_irq, M68K_IRQC_LEVEL_NUM);
 }
 
-static void m68k_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool m68k_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     m68k_set_irq(n, M68K_IRQC_LEVEL_7, 1);
+
+    return true;
 }
 
 static const VMStateDescription vmstate_m68k_irqc = {
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 9d52ca6613..8631a226cd 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -227,13 +227,15 @@  static void glue_auxmode_set_irq(void *opaque, int irq, int level)
     s->auxmode = level;
 }
 
-static void glue_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool glue_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     GLUEState *s = GLUE(n);
 
     /* Hold NMI active for 100ms */
     GLUE_set_irq(s, GLUE_IRQ_IN_NMI, 1);
     timer_mod(s->nmi_release, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 100);
+
+    return true;
 }
 
 static void glue_nmi_release(void *opaque)
diff --git a/hw/misc/macio/gpio.c b/hw/misc/macio/gpio.c
index c8ac5633b2..0a7214421c 100644
--- a/hw/misc/macio/gpio.c
+++ b/hw/misc/macio/gpio.c
@@ -182,10 +182,12 @@  static void macio_gpio_reset(DeviceState *dev)
     macio_set_gpio(s, 1, true);
 }
 
-static void macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool macio_gpio_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     macio_set_gpio(MACIO_GPIO(n), 9, true);
     macio_set_gpio(MACIO_GPIO(n), 9, false);
+
+    return true;
 }
 
 static void macio_gpio_class_init(ObjectClass *oc, void *data)
diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c
index 44b1fbbc93..38e69f3b39 100644
--- a/hw/ppc/pnv.c
+++ b/hw/ppc/pnv.c
@@ -2309,13 +2309,14 @@  static void pnv_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg)
     }
 }
 
-static void pnv_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool pnv_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     CPUState *cs;
 
     CPU_FOREACH(cs) {
         async_run_on_cpu(cs, pnv_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL);
     }
+    return true;
 }
 
 static void pnv_machine_class_init(ObjectClass *oc, void *data)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 4921198b9d..d298068169 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3464,13 +3464,14 @@  void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg)
     }
 }
 
-static void spapr_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool spapr_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     CPUState *cs;
 
     CPU_FOREACH(cs) {
         async_run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL);
     }
+    return true;
 }
 
 int spapr_lmb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index f22f61b8b6..af7e6c632a 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -570,11 +570,13 @@  static HotplugHandler *s390_get_hotplug_handler(MachineState *machine,
     return NULL;
 }
 
-static void s390_nmi(NMIState *n, int cpu_index, Error **errp)
+static bool s390_nmi(NMIState *n, int cpu_index, Error **errp)
 {
     CPUState *cs = qemu_get_cpu(cpu_index);
 
     s390_cpu_restart(S390_CPU(cs));
+
+    return true;
 }
 
 static ram_addr_t s390_fixup_ram_size(ram_addr_t sz)
diff --git a/include/hw/nmi.h b/include/hw/nmi.h
index fff41bebc6..3e827a254a 100644
--- a/include/hw/nmi.h
+++ b/include/hw/nmi.h
@@ -37,7 +37,8 @@  typedef struct NMIState NMIState;
 struct NMIClass {
     InterfaceClass parent_class;
 
-    void (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
+    /** Returns: %true on success, %false on error. */
+    bool (*nmi_monitor_handler)(NMIState *n, int cpu_index, Error **errp);
 };
 
 void nmi_monitor_handle(int cpu_index, Error **errp);