[PATCH v2] hw/virtio/virtio-pci: Avoid compiler warning with -Wshadow

Thomas Huth posted 1 patch 7 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231004095302.99037-1-thuth@redhat.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>
hw/virtio/virtio-pci.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
[PATCH v2] hw/virtio/virtio-pci: Avoid compiler warning with -Wshadow
Posted by Thomas Huth 7 months ago
"len" is used as parameter of the functions virtio_write_config()
and virtio_read_config(), and additionally as a local variable,
so this causes a compiler warning when compiling with "-Wshadow"
and can be confusing for the reader. Rename the local variables
to "caplen" to avoid this problem.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 v2: Fix virtio_read_config() function as well

 hw/virtio/virtio-pci.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index edbc0daa18..abebd0075a 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -780,15 +780,15 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
                                                                   pci_cfg_data),
                        sizeof cfg->pci_cfg_data)) {
         uint32_t off;
-        uint32_t len;
+        uint32_t caplen;
 
         cfg = (void *)(proxy->pci_dev.config + proxy->config_cap);
         off = le32_to_cpu(cfg->cap.offset);
-        len = le32_to_cpu(cfg->cap.length);
+        caplen = le32_to_cpu(cfg->cap.length);
 
-        if (len == 1 || len == 2 || len == 4) {
-            assert(len <= sizeof cfg->pci_cfg_data);
-            virtio_address_space_write(proxy, off, cfg->pci_cfg_data, len);
+        if (caplen == 1 || caplen == 2 || caplen == 4) {
+            assert(caplen <= sizeof cfg->pci_cfg_data);
+            virtio_address_space_write(proxy, off, cfg->pci_cfg_data, caplen);
         }
     }
 }
@@ -804,15 +804,15 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
                                                                   pci_cfg_data),
                        sizeof cfg->pci_cfg_data)) {
         uint32_t off;
-        uint32_t len;
+        uint32_t caplen;
 
         cfg = (void *)(proxy->pci_dev.config + proxy->config_cap);
         off = le32_to_cpu(cfg->cap.offset);
-        len = le32_to_cpu(cfg->cap.length);
+        caplen = le32_to_cpu(cfg->cap.length);
 
-        if (len == 1 || len == 2 || len == 4) {
-            assert(len <= sizeof cfg->pci_cfg_data);
-            virtio_address_space_read(proxy, off, cfg->pci_cfg_data, len);
+        if (caplen == 1 || caplen == 2 || caplen == 4) {
+            assert(caplen <= sizeof cfg->pci_cfg_data);
+            virtio_address_space_read(proxy, off, cfg->pci_cfg_data, caplen);
         }
     }
 
-- 
2.41.0
Re: [PATCH v2] hw/virtio/virtio-pci: Avoid compiler warning with -Wshadow
Posted by Markus Armbruster 7 months ago
Thomas Huth <thuth@redhat.com> writes:

> "len" is used as parameter of the functions virtio_write_config()
> and virtio_read_config(), and additionally as a local variable,
> so this causes a compiler warning when compiling with "-Wshadow"
> and can be confusing for the reader. Rename the local variables
> to "caplen" to avoid this problem.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

v1 unqueued, this one queued.  Thanks!
Re: [PATCH v2] hw/virtio/virtio-pci: Avoid compiler warning with -Wshadow
Posted by Philippe Mathieu-Daudé 7 months ago
On 4/10/23 11:53, Thomas Huth wrote:
> "len" is used as parameter of the functions virtio_write_config()
> and virtio_read_config(), and additionally as a local variable,
> so this causes a compiler warning when compiling with "-Wshadow"
> and can be confusing for the reader. Rename the local variables
> to "caplen" to avoid this problem.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   v2: Fix virtio_read_config() function as well
> 
>   hw/virtio/virtio-pci.c | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>