]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
ARM/vgic: Fix variable shadowing in vgic_to_sgi()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 27 Aug 2024 23:33:19 +0000 (00:33 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 28 Aug 2024 09:49:26 +0000 (10:49 +0100)
for_each_set_bit() allocates its own variable intentionally as loop-scope
only.  Unfortunately, this causes the inner 'i' to shadow the outer 'i', and
violates MISRA Rule 5.3.

Drop the outermost 'i' and 'vcpuid' variables, moving them into a more narrow
scope and correcting them to be unsigned which they should have been all
along.  Update the printk() formatting of vcpuid to match.

Fixes: 9429f1a6c475 ("ARM/vgic: Use for_each_set_bit() in vgic_to_sgi()")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
xen/arch/arm/vgic.c

index 8ffe099bcb5f2fdc3b56a2d5389b875addb926c6..c563ba93af22be6504ea3e2c371c1853d713de84 100644 (file)
@@ -468,8 +468,6 @@ bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum gic_sgi_mode irqmode,
                  int virq, const struct sgi_target *target)
 {
     struct domain *d = v->domain;
-    int vcpuid;
-    int i;
     unsigned int base, bitmap;
 
     ASSERT( virq < 16 );
@@ -483,12 +481,13 @@ bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum gic_sgi_mode irqmode,
 
         for_each_set_bit ( i, bitmap )
         {
-            vcpuid = base + i;
+            unsigned int vcpuid = base + i;
+
             if ( vcpuid >= d->max_vcpus || d->vcpu[vcpuid] == NULL ||
                  !is_vcpu_online(d->vcpu[vcpuid]) )
             {
                 gprintk(XENLOG_WARNING,
-                        "vGIC: write %#"PRIregister", target->list=%#x, bad target vcpu%d\n",
+                        "vGIC: write %#"PRIregister", target->list=%#x, bad target vcpu%u\n",
                         sgir, target->list, vcpuid);
                 continue;
             }
@@ -497,7 +496,7 @@ bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum gic_sgi_mode irqmode,
         break;
     case SGI_TARGET_OTHERS:
         perfc_incr(vgic_sgi_others);
-        for ( i = 0; i < d->max_vcpus; i++ )
+        for ( unsigned int i = 0; i < d->max_vcpus; i++ )
         {
             if ( i != current->vcpu_id && d->vcpu[i] != NULL &&
                  is_vcpu_online(d->vcpu[i]) )