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

Ani Sinha posted 1 patch 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231003103601.6245-1-anisinha@redhat.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Peter Xu <peterx@redhat.com>, Jason Wang <jasowang@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
hw/i386/intel_iommu.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] hw/i386/intel_iommu: changes towards enabling -Wshadow=local
Posted by Ani Sinha 7 months ago
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: <87r0mqlf9x.fsf@pond.sub.org>
   https://lore.kernel.org/qemu-devel/87r0mqlf9x.fsf@pond.sub.org

Signed-off-by: Ani Sinha <anisinha@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
---
 hw/i386/intel_iommu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

See also 
Peter's changes from
https://lore.kernel.org/r/20230922160410.138786-1-peterx@redhat.com.
This patch is same as above.

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index c0ce896668..2c832ab68b 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -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);
 }
 
-- 
2.42.0


Re: [PATCH] hw/i386/intel_iommu: changes towards enabling -Wshadow=local
Posted by Ani Sinha 7 months ago

> On 03-Oct-2023, at 4:06 PM, Ani Sinha <anisinha@redhat.com> wrote:
> 
> 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: <87r0mqlf9x.fsf@pond.sub.org>
>   https://lore.kernel.org/qemu-devel/87r0mqlf9x.fsf@pond.sub.org
> 
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> Reviewed-by: Peter Xu <peterx@redhat.com>

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.

> ---
> hw/i386/intel_iommu.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> See also 
> Peter's changes from
> https://lore.kernel.org/r/20230922160410.138786-1-peterx@redhat.com.
> This patch is same as above.
> 
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index c0ce896668..2c832ab68b 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -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);
> }
> 
> -- 
> 2.42.0
>