Commit 2527d73807 for qemu.org

commit 2527d738072b9d9d8a2c8262127003c6aa9f9983
Author: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Date:   Mon Nov 9 13:52:08 2026 +0000

    hw/intc/arm_gic: move num-priority-bits check

    We check the num-priority-bits property for sane values in
    arm_gic_realize(), but the property is defined on the "common"
    superclass, so it is present also for TYPE_KVM_ARM_GIC.  Currently
    this misplaced check is harmless, beacuse the KVM subclass never
    looks at the property value.  However, we are about to make a change
    that will want to use the property value in code called from the
    common class's reset method.

    Move num-priority-bits property value check to the common class
    realize method, where it belongs.

    Suggested-by: Peter Maydell <peter.maydell@linaro.org>
    Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
    Message-id: 20261106-gic_read_bpr_from_property-v2-2-9f096cce4814@linaro.org
    [PMM: rewrote commit message, moved patch before the change that
     it is a prerequisite for]
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
index 4d4b79e6f3..b60f1f630b 100644
--- a/hw/intc/arm_gic.c
+++ b/hw/intc/arm_gic.c
@@ -2117,16 +2117,6 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)
         return;
     }

-    if (s->n_prio_bits > GIC_MAX_PRIORITY_BITS ||
-       (s->virt_extn ? s->n_prio_bits < GIC_VIRT_MAX_GROUP_PRIO_BITS :
-        s->n_prio_bits < GIC_MIN_PRIORITY_BITS)) {
-        error_setg(errp, "num-priority-bits cannot be greater than %d"
-                   " or less than %d", GIC_MAX_PRIORITY_BITS,
-                   s->virt_extn ? GIC_VIRT_MAX_GROUP_PRIO_BITS :
-                   GIC_MIN_PRIORITY_BITS);
-        return;
-    }
-
     /* This creates distributor, main CPU interface (s->cpuiomem[0]) and if
      * enabled, virtualization extensions related interfaces (main virtual
      * interface (s->vifaceiomem[0]) and virtual CPU interface).
diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c
index 304d89cf56..a7c0763ab6 100644
--- a/hw/intc/arm_gic_common.c
+++ b/hw/intc/arm_gic_common.c
@@ -233,6 +233,16 @@ static void arm_gic_common_realize(DeviceState *dev, Error **errp)
          */
         s->num_lrs = 4;
     }
+
+    if (s->n_prio_bits > GIC_MAX_PRIORITY_BITS ||
+       (s->virt_extn ? s->n_prio_bits < GIC_VIRT_MAX_GROUP_PRIO_BITS :
+        s->n_prio_bits < GIC_MIN_PRIORITY_BITS)) {
+        error_setg(errp, "num-priority-bits cannot be greater than %d"
+                   " or less than %d", GIC_MAX_PRIORITY_BITS,
+                   s->virt_extn ? GIC_VIRT_MAX_GROUP_PRIO_BITS :
+                   GIC_MIN_PRIORITY_BITS);
+        return;
+    }
 }

 static inline void arm_gic_common_reset_irq_state(GICState *s, int cidx,