Skip to contentSkip to conversation

hw/i386/intel_iommu: changes towards enabling -Wshadow=local

PATCH In review Ani Sinha 1 participant 2 messages Oct 3, 2023

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH 1/1 hw/i386/intel_iommu: changes towards enabling -Wshadow=local

Code changes that addresses all compiler complaints coming from enabling -Wshadow flags. Enabling -Wshadow catches cases of local variables shadowing other local variables or parameters. These makes the code confusing and/or adds bugs that are difficult to catch.

See also

Subject: Help wanted for enabling -Wshadow=local
Message-Id: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]

---
 hw/i386/intel_iommu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

See also
Peter's changes from
https://lore.kernel.org/r/[email protected].
This patch is same as above.

hw/i386/intel_iommu.c +4 -4
index c0ce896668..2c832ab68b 100644
@@ -3744,7 +3744,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus,
 /* Unmap the whole range in the notifier's scope. */
 static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
 {
-    hwaddr size, remain;
+    hwaddr total, remain;
     hwaddr start = n->start;
     hwaddr end = n->end;
     IntelIOMMUState *s = as->iommu_state;
@@ -3765,7 +3765,7 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
     }
 
     assert(start <= end);
-    size = remain = end - start + 1;
+    total = remain = end - start + 1;
 
     while (remain >= VTD_PAGE_SIZE) {
         IOMMUTLBEvent event;
@@ -3793,10 +3793,10 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
     trace_vtd_as_unmap_whole(pci_bus_num(as->bus),
                              VTD_PCI_SLOT(as->devfn),
                              VTD_PCI_FUNC(as->devfn),
-                             n->start, size);
+                             n->start, total);
 
     map.iova = n->start;
-    map.size = size - 1; /* Inclusive */
+    map.size = total - 1; /* Inclusive */
     iova_tree_remove(as->iova_tree, map);
 }
 
Signature · 1 line
2.42.0
author
#1 lore raw
Quoted 11 lines · Ani Sinha

Code changes that addresses all compiler complaints coming from enabling -Wshadow flags. Enabling -Wshadow catches cases of local variables shadowing other local variables or parameters. These makes the code confusing and/or adds bugs that are difficult to catch.

See also

Quoted 7 lines

Subject: Help wanted for enabling -Wshadow=local
Message-Id: <[email protected]>
https://lore.kernel.org/qemu-devel/[email protected]

Although I sent this for completeness, I see this already got merged

https://gitlab.com/qemu-project/qemu/-/commit/a082739eb390d2aad679b5efa9afc40cfa2a496d

So we can toss this patch out.

Quoted 47 lines

---
hw/i386/intel_iommu.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)

See also
Peter's changes from
https://lore.kernel.org/r/[email protected].
This patch is same as above.

hw/i386/intel_iommu.c +4 -4
index c0ce896668..2c832ab68b 100644
@@ -3744,7 +3744,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus,
 /* Unmap the whole range in the notifier's scope. */
 static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
 {
-    hwaddr size, remain;
+    hwaddr total, remain;
    hwaddr start = n->start;
    hwaddr end = n->end;
    IntelIOMMUState *s = as->iommu_state;
@@ -3765,7 +3765,7 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
    }
 
    assert(start <= end);
-    size = remain = end - start + 1;
+    total = remain = end - start + 1;
 
    while (remain >= VTD_PAGE_SIZE) {
        IOMMUTLBEvent event;
@@ -3793,10 +3793,10 @@ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
    trace_vtd_as_unmap_whole(pci_bus_num(as->bus),
                             VTD_PCI_SLOT(as->devfn),
                             VTD_PCI_FUNC(as->devfn),
-                             n->start, size);
+                             n->start, total);
 
    map.iova = n->start;
-    map.size = size - 1; /* Inclusive */
+    map.size = total - 1; /* Inclusive */
    iova_tree_remove(as->iova_tree, map);
 }
 
Signature · 1 line
2.42.0