Skip to contentSkip to conversation

ppc: Clean up local variable shadowing

PATCH In review Cédric Le Goater 5 participants 39 messages Sep 18, 2023 – Oct 4, 2023

lore
Share & tools
lore
#0 lore raw

cover ppc: Clean up local variable shadowing

Hello,

Here is a first round of cleanups for local variable shadowing warrnings.

Thanks,

C.

Cédric Le Goater (8):
hw/ppc: Clean up local variable shadowing in _FDT helper routine pnv/psi: Clean up local variable shadowing
spapr: Clean up local variable shadowing in spapr_dt_cpus()
spapr: Clean up local variable shadowing in spapr_init_cpus()
spapr: Clean up local variable shadowing in spapr_get_fw_dev_path() spapr/drc: Clean up local variable shadowing in
rtas_ibm_configure_connector()
spapr/pci: Clean up local variable shadowing in spapr_phb_realize() spapr/drc: Clean up local variable shadowing in prop_get_fdt()

 include/hw/ppc/fdt.h |  8 ++++----
 hw/ppc/pnv_psi.c     |  5 +++--
 hw/ppc/spapr.c       | 42 +++++++++++++++++++++++-------------------
 hw/ppc/spapr_drc.c   | 12 +++++-------
 hw/ppc/spapr_pci.c   |  6 +++---
 5 files changed, 38 insertions(+), 35 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/8 hw/ppc: Clean up local variable shadowing in _FDT helper routine

this fixes numerous warnings of this type :

In file included from ../hw/ppc/spapr_pci.c:43:
../hw/ppc/spapr_pci.c: In function ‘spapr_dt_phb’:
../include/hw/ppc/fdt.h:18:13: warning: declaration of ‘ret’ shadows a previous local [-Wshadow=compatible-local]

     18 |         int ret = (exp);                                           \
        |             ^~~
  ../hw/ppc/spapr_pci.c:2355:5: note: in expansion of macro ‘_FDT’
   2355 |     _FDT(bus_off = fdt_add_subnode(fdt, 0, phb->dtbusname));
        |     ^~~~

../hw/ppc/spapr_pci.c:2311:24: note: shadowed declaration is here
2311 | int bus_off, i, j, ret;
| ^~~

---
 include/hw/ppc/fdt.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/ppc/fdt.h +4 -4
index a8cd85069fe0..b56ac2a8cbb5 100644
@@ -15,10 +15,10 @@
 
 #define _FDT(exp)                                                  \
     do {                                                           \
-        int ret = (exp);                                           \
-        if (ret < 0) {                                             \
-            error_report("error creating device tree: %s: %s",   \
-                    #exp, fdt_strerror(ret));                      \
+        int _ret = (exp);                                          \
+        if (_ret < 0) {                                            \
+            error_report("error creating device tree: %s: %s",     \
+                    #exp, fdt_strerror(_ret));                     \
             exit(1);                                               \
         }                                                          \
     } while (0)
Signature · 1 line
2.41.0
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] hw/ppc: Clean up local variable shadowing in _FDT helper routine

Quoted 14 lines · Cédric Le Goater

this fixes numerous warnings of this type :

In file included from ../hw/ppc/spapr_pci.c:43:
../hw/ppc/spapr_pci.c: In function ‘spapr_dt_phb’:

   ../include/hw/ppc/fdt.h:18:13: warning: declaration of ‘ret’ shadows a previous local [-Wshadow=compatible-local]
      18 |         int ret = (exp);                                           \
         |             ^~~
   ../hw/ppc/spapr_pci.c:2355:5: note: in expansion of macro ‘_FDT’
    2355 |     _FDT(bus_off = fdt_add_subnode(fdt, 0, phb->dtbusname));
         |     ^~~~
   ../hw/ppc/spapr_pci.c:2311:24: note: shadowed declaration is here
    2311 |     int bus_off, i, j, ret;
         |                        ^~~
Quoted 1 line
Quoted 23 lines
---
  include/hw/ppc/fdt.h | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
include/hw/ppc/fdt.h +4 -4
index a8cd85069fe0..b56ac2a8cbb5 100644
@@ -15,10 +15,10 @@
 
  #define _FDT(exp)                                                  \
      do {                                                           \
-        int ret = (exp);                                           \
-        if (ret < 0) {                                             \
-            error_report("error creating device tree: %s: %s",   \
-                    #exp, fdt_strerror(ret));                      \
+        int _ret = (exp);                                          \
+        if (_ret < 0) {                                            \
+            error_report("error creating device tree: %s: %s",     \
+                    #exp, fdt_strerror(_ret));                     \
              exit(1);                                               \
          }                                                          \
      } while (0)
#3 lore raw

PATCH 2/8 pnv/psi: Clean up local variable shadowing

In reply to Cédric Le Goater

to fix :

../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local]

    741 |                 hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
        |                        ^~~~

../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
| ~~~~~~~^~~~

---
 hw/ppc/pnv_psi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/ppc/pnv_psi.c +3 -2
index daaa2f0575fd..26460d210deb 100644
@@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
             }
         } else {
             if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
-                hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
-                memory_region_add_subregion(sysmem, addr,
+                hwaddr esb_addr =
+                    val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
+                memory_region_add_subregion(sysmem, esb_addr,
                                             &psi9->source.esb_mmio);
             }
         }
Signature · 1 line
2.41.0
Reviewed-by on v1 2/8
#4 lore raw

Re: [PATCH 2/8] pnv/psi: Clean up local variable shadowing

Quoted 20 lines · Cédric Le Goater

to fix :

../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local]

     741 |                 hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
         |                        ^~~~

../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
| ~~~~~~~^~~~

---
  hw/ppc/pnv_psi.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/ppc/pnv_psi.c +0 -0
index daaa2f0575fd..26460d210deb 100644

hw/ppc/pnv_psi.c static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr, · line 741

Quoted 6 lines
hw/ppc/pnv_psi.c +1 -2
@@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
              }
          } else {
              if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
-                hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
-                memory_region_add_subregion(sysmem, addr,
+                hwaddr esb_addr =

While at it, we may want to move the declaration to the beginning of the function. Anyways,

Quoted 5 lines
hw/ppc/pnv_psi.c +2 -0
+                    val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
+                memory_region_add_subregion(sysmem, esb_addr,
                                              &psi9->source.esb_mmio);
              }
          }
#5 lore raw

Re: [PATCH 2/8] pnv/psi: Clean up local variable shadowing

Quoted 18 lines · Harsh Prateek Bora
Quoted 15 lines · Cédric Le Goater

to fix :

   ../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
   ../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local] 741 |                 hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K); |                        ^~~~
   ../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
     702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
         |                                                 ~~~~~~~^~~~

---
  hw/ppc/pnv_psi.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

hw/ppc/pnv_psi.c static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr, · line 741

Quoted 11 lines
hw/ppc/pnv_psi.c +1 -2
index daaa2f0575fd..26460d210deb 100644
@@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
               }
           } else {
               if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
-                hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
-                memory_region_add_subregion(sysmem, addr,
+                hwaddr esb_addr =

While at it, we may want to move the declaration to the beginning of the function.

I am more in favor of declaring the variables where they are needed. I think it is better pratice since it identifies a functional block which could be move in a external routine at some point if it becomes too complex.

Quoted 3 lines

Anyways,

Thanks,

C.

Quoted 6 lines
Quoted 6 lines
hw/ppc/pnv_psi.c +2 -0
+                    val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
+                memory_region_add_subregion(sysmem, esb_addr,
                                               &psi9->source.esb_mmio);
               }
           }
#6 lore raw

Re: [PATCH 2/8] pnv/psi: Clean up local variable shadowing

Quoted 31 lines · Cédric Le Goater
Quoted 16 lines · Harsh Prateek Bora
Quoted 15 lines · Cédric Le Goater

to fix :

   ../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
   ../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local] 741 |                 hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K); |                        ^~~~
   ../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
     702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
         |                                                 ~~~~~~~^~~~

---
  hw/ppc/pnv_psi.c | 5 +++--

  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 13 lines

hw/ppc/pnv_psi.c static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr, · line 741

Quoted 11 lines
hw/ppc/pnv_psi.c +1 -2
index daaa2f0575fd..26460d210deb 100644
@@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
               }
           } else {
               if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
-                hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
-                memory_region_add_subregion(sysmem, addr,
+                hwaddr esb_addr =

While at it, we may want to move the declaration to the beginning of the function.

Quoted 4 lines

I am more in favor of declaring the variables where they are needed. I think it is better pratice since it identifies a functional block which could be move in a external routine at some point if it becomes too complex.

I'm old-fashioned and prefer my declarations in one place, where I can find them easily, except perhaps for for-loop counters. I suspect when a function is big enough so that moving declarations to inner blocks improves it, factoring out these inner blocks would improve it more.

My other reason is the risk for accidental shadowing, but us enabling -Wshadow=local will render that point moot.

Maintainers get to decide such matters of taste, and I'm not the maintainer here :)

Quoted 15 lines
Quoted 2 lines

Anyways,

Thanks,

C.

Quoted 6 lines
Quoted 6 lines
hw/ppc/pnv_psi.c +2 -0
+                    val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
+                memory_region_add_subregion(sysmem, esb_addr,
                                               &psi9->source.esb_mmio);
               }
           }
#7 lore raw

Re: [PATCH 2/8] pnv/psi: Clean up local variable shadowing

Quoted 33 lines · Markus Armbruster
Quoted 31 lines · Cédric Le Goater
Quoted 29 lines · Harsh Prateek Bora
Quoted 20 lines · Cédric Le Goater

to fix :

   ../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
   ../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local] 741 |                 hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K); |                        ^~~~
   ../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
     702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
         |                                                 ~~~~~~~^~~~

---
   hw/ppc/pnv_psi.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
hw/ppc/pnv_psi.c +0 -0
index daaa2f0575fd..26460d210deb 100644

hw/ppc/pnv_psi.c static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr, · line 741

Quoted 6 lines
hw/ppc/pnv_psi.c +1 -2
@@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
               }
           } else {
               if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
-                hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
-                memory_region_add_subregion(sysmem, addr,
+                hwaddr esb_addr =

While at it, we may want to move the declaration to the beginning of the function.

Quoted 7 lines
Quoted 4 lines

I am more in favor of declaring the variables where they are needed. I think it is better pratice since it identifies a functional block which could be move in a external routine at some point if it becomes too complex.

I'm old-fashioned and prefer my declarations in one place, where I can find them easily, except perhaps for for-loop counters.

This is also a good practice since too much local variables in a routine is a good sign of further splitting need. Anyway as you said, we have -Wshadow=local, we should be safe.

Thanks,

C.

Quoted 25 lines

I suspect when
a function is big enough so that moving declarations to inner blocks improves it, factoring out these inner blocks would improve it more.

My other reason is the risk for accidental shadowing, but us enabling -Wshadow=local will render that point moot.

Maintainers get to decide such matters of taste, and I'm not the maintainer here :)

Quoted 15 lines
Quoted 2 lines

Anyways,

Thanks,

C.

Quoted 6 lines
Quoted 6 lines
hw/ppc/pnv_psi.c +2 -0
+                    val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
+                memory_region_add_subregion(sysmem, esb_addr,
                                               &psi9->source.esb_mmio);
               }
           }
#8 lore raw

PATCH 3/8 spapr: Clean up local variable shadowing in spapr_dt_cpus()

In reply to Cédric Le Goater

Introduce a helper routine defining one CPU device node to fix this warning :

../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a previous local [-Wshadow=compatible-local]

    812 |         CPUState *cs = rev[i];
        |                   ^~
  ../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
    786 |     CPUState *cs;
        |               ^~
---
 hw/ppc/spapr.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
hw/ppc/spapr.c +21 -15
index de3c616b4637..d89f0fd496b6 100644
@@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,
                               pcc->lrg_decr_bits)));
 }
 
+static void spapr_dt_one_cpu(void *fdt, SpaprMachineState *spapr, CPUState *cs,
+                             int cpus_offset)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    int index = spapr_get_vcpu_id(cpu);
+    DeviceClass *dc = DEVICE_GET_CLASS(cs);
+    g_autofree char *nodename = NULL;
+    int offset;
+
+    if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
+        return;
+    }
+
+    nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
+    offset = fdt_add_subnode(fdt, cpus_offset, nodename);
+    _FDT(offset);
+    spapr_dt_cpu(cs, fdt, offset, spapr);
+}
+
+
 static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
 {
     CPUState **rev;
@@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
     }
 
     for (i = n_cpus - 1; i >= 0; i--) {
-        CPUState *cs = rev[i];
-        PowerPCCPU *cpu = POWERPC_CPU(cs);
-        int index = spapr_get_vcpu_id(cpu);
-        DeviceClass *dc = DEVICE_GET_CLASS(cs);
-        g_autofree char *nodename = NULL;
-        int offset;
-
-        if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
-            continue;
-        }
-
-        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
-        offset = fdt_add_subnode(fdt, cpus_offset, nodename);
-        _FDT(offset);
-        spapr_dt_cpu(cs, fdt, offset, spapr);
+        spapr_dt_one_cpu(fdt, spapr, rev[i], cpus_offset);
     }
 
     g_free(rev);
Signature · 1 line
2.41.0
Reviewed-by on v1 3/8
#9 lore raw

Re: [PATCH 3/8] spapr: Clean up local variable shadowing in spapr_dt_cpus()

Quoted 57 lines · Cédric Le Goater

Introduce a helper routine defining one CPU device node to fix this warning :

../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a previous local [-Wshadow=compatible-local]

     812 |         CPUState *cs = rev[i];
         |                   ^~
   ../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
     786 |     CPUState *cs;
         |               ^~
---
  hw/ppc/spapr.c | 36 +++++++++++++++++++++---------------
  1 file changed, 21 insertions(+), 15 deletions(-)
hw/ppc/spapr.c +20 -6
index de3c616b4637..d89f0fd496b6 100644
@@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,
                                pcc->lrg_decr_bits)));
  }
 
+static void spapr_dt_one_cpu(void *fdt, SpaprMachineState *spapr, CPUState *cs,
+                             int cpus_offset)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    int index = spapr_get_vcpu_id(cpu);
+    DeviceClass *dc = DEVICE_GET_CLASS(cs);
+    g_autofree char *nodename = NULL;
+    int offset;
+
+    if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
+        return;
+    }
+
+    nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
+    offset = fdt_add_subnode(fdt, cpus_offset, nodename);
+    _FDT(offset);
+    spapr_dt_cpu(cs, fdt, offset, spapr);
+}
+
+
  static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
  {
      CPUState **rev;
@@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
      }
 
      for (i = n_cpus - 1; i >= 0; i--) {
-        CPUState *cs = rev[i];
-        PowerPCCPU *cpu = POWERPC_CPU(cs);
-        int index = spapr_get_vcpu_id(cpu);
-        DeviceClass *dc = DEVICE_GET_CLASS(cs);
-        g_autofree char *nodename = NULL;
-        int offset;

hw/ppc/spapr.c static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr) · line 832

Quoted 10 lines
hw/ppc/spapr.c +1 -9
-
-        if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
-            continue;
-        }
-
-        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
-        offset = fdt_add_subnode(fdt, cpus_offset, nodename);
-        _FDT(offset);
-        spapr_dt_cpu(cs, fdt, offset, spapr);
+        spapr_dt_one_cpu(fdt, spapr, rev[i], cpus_offset);

Do we want to replace the call to spapr_dt_cpu in spapr_core_dt_populate() with the _one_ as well?
Not sure about the implication of additional instructions there.

Also, could this code insider wrapper become part of spapr_dt_cpu() itself? If can't, do we want a better renaming of wrapper here?

Otherwise,

Quoted 3 lines
hw/ppc/spapr.c +0 -0
      }
 
      g_free(rev);
#10 lore raw

Re: [PATCH 3/8] spapr: Clean up local variable shadowing in spapr_dt_cpus()

Quoted 64 lines · Harsh Prateek Bora
Quoted 61 lines · Cédric Le Goater

Introduce a helper routine defining one CPU device node to fix this warning :

   ../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
   ../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a previous local [-Wshadow=compatible-local] 812 |         CPUState *cs = rev[i];
         |                   ^~
   ../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
     786 |     CPUState *cs;
         |               ^~

---
  hw/ppc/spapr.c | 36 +++++++++++++++++++++---------------

  1 file changed, 21 insertions(+), 15 deletions(-)
hw/ppc/spapr.c +20 -12
index de3c616b4637..d89f0fd496b6 100644
@@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,
                                 pcc->lrg_decr_bits)));
   }
+static void spapr_dt_one_cpu(void *fdt, SpaprMachineState *spapr, CPUState *cs,
+                             int cpus_offset)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    int index = spapr_get_vcpu_id(cpu);
+    DeviceClass *dc = DEVICE_GET_CLASS(cs);
+    g_autofree char *nodename = NULL;
+    int offset;
+
+    if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
+        return;
+    }
+
+    nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
+    offset = fdt_add_subnode(fdt, cpus_offset, nodename);
+    _FDT(offset);
+    spapr_dt_cpu(cs, fdt, offset, spapr);
+}
+
+
   static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
   {
       CPUState **rev;
@@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
       }
       for (i = n_cpus - 1; i >= 0; i--) {
-        CPUState *cs = rev[i];
-        PowerPCCPU *cpu = POWERPC_CPU(cs);
-        int index = spapr_get_vcpu_id(cpu);
-        DeviceClass *dc = DEVICE_GET_CLASS(cs);
-        g_autofree char *nodename = NULL;
-        int offset;
-
-        if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
-            continue;
-        }
-
-        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
Quoted 8 lines

hw/ppc/spapr.c static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr) · line 832

Quoted 4 lines
hw/ppc/spapr.c +1 -3
-        offset = fdt_add_subnode(fdt, cpus_offset, nodename);
-        _FDT(offset);
-        spapr_dt_cpu(cs, fdt, offset, spapr);
+        spapr_dt_one_cpu(fdt, spapr, rev[i], cpus_offset);

Do we want to replace the call to spapr_dt_cpu in spapr_core_dt_populate() with the _one_ as well?
Not sure about the implication of additional instructions there.

yeah may be we could rework spapr_dt_one_cpu() and spapr_core_dt_populate() in a single routine. They are similar. It can come later.

Quoted 2 lines

Also, could this code insider wrapper become part of spapr_dt_cpu() itself? If can't, do we want a better renaming of wrapper here?

I am open to proposal :)

Thanks

C.

Quoted 6 lines

Otherwise,

Quoted 2 lines
hw/ppc/spapr.c +0 -0
       }
       g_free(rev);
#11 lore raw

Re: [PATCH 3/8] spapr: Clean up local variable shadowing in spapr_dt_cpus()

Quoted 78 lines · Cédric Le Goater,
Quoted 8 lines · Harsh Prateek Bora
Quoted 5 lines · Cédric Le Goater

Introduce a helper routine defining one CPU device node to fix this warning :

../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a

previous local [-Wshadow=compatible-local]

Quoted 11 lines
Quoted 11 lines
     812 |         CPUState *cs = rev[i];
         |                   ^~
   ../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
     786 |     CPUState *cs;
         |               ^~
---
  hw/ppc/spapr.c | 36 +++++++++++++++++++++---------------
  1 file changed, 21 insertions(+), 15 deletions(-)
Quoted 5 lines

hw/ppc/spapr.c static void spapr_dt_cpu(CPUState *cs, void *fdt,

Quoted 5 lines
hw/ppc/spapr.c +0 -0
index de3c616b4637..d89f0fd496b6 100644
@@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt,

int offset,

Quoted 3 lines

hw/ppc/spapr.c static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,

Quoted 3 lines
hw/ppc/spapr.c +1 -0
                                pcc->lrg_decr_bits)));
  }
+static void spapr_dt_one_cpu(void *fdt, SpaprMachineState *spapr,

CPUState *cs,

Quoted 15 lines
Quoted 15 lines
hw/ppc/spapr.c +15 -0
+                             int cpus_offset)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    int index = spapr_get_vcpu_id(cpu);
+    DeviceClass *dc = DEVICE_GET_CLASS(cs);
+    g_autofree char *nodename = NULL;
+    int offset;
+
+    if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
+        return;
+    }
+
+    nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
+    offset = fdt_add_subnode(fdt, cpus_offset, nodename);
+    _FDT(offset);
Quoted 8 lines

hw/ppc/spapr.c static void spapr_dt_cpus(void *fdt,

Quoted 8 lines
hw/ppc/spapr.c +4 -0
+    spapr_dt_cpu(cs, fdt, offset, spapr);
+}
+
+
  static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
  {
      CPUState **rev;
@@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt,

SpaprMachineState *spapr)

Quoted 14 lines
Quoted 14 lines
hw/ppc/spapr.c +0 -12
      }
      for (i = n_cpus - 1; i >= 0; i--) {
-        CPUState *cs = rev[i];
-        PowerPCCPU *cpu = POWERPC_CPU(cs);
-        int index = spapr_get_vcpu_id(cpu);
-        DeviceClass *dc = DEVICE_GET_CLASS(cs);
-        g_autofree char *nodename = NULL;
-        int offset;
-
-        if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
-            continue;
-        }
-
-        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
Quoted 8 lines

hw/ppc/spapr.c static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr) · line 832

Quoted 4 lines
hw/ppc/spapr.c +1 -3
-        offset = fdt_add_subnode(fdt, cpus_offset, nodename);
-        _FDT(offset);
-        spapr_dt_cpu(cs, fdt, offset, spapr);
+        spapr_dt_one_cpu(fdt, spapr, rev[i], cpus_offset);

Do we want to replace the call to spapr_dt_cpu in spapr_core_dt_populate() with the _one_ as well?
Not sure about the implication of additional instructions there.

Quoted 9 lines

yeah may be we could rework spapr_dt_one_cpu() and spapr_core_dt_populate() in a single routine. They are similar. It can come later.

Quoted 1 line

Also, could this code insider wrapper become part of spapr_dt_cpu()

itself?

Quoted 1 line

If can't, do we want a better renaming of wrapper here?

I am open to proposal :)

How about spapr_dt_cpu_prepare() ?

Quoted 14 lines

Thanks

C.

Quoted 6 lines

Otherwise,

Quoted 2 lines
hw/ppc/spapr.c +0 -0
      }
      g_free(rev);
#12 lore raw

Re: [PATCH 3/8] spapr: Clean up local variable shadowing in spapr_dt_cpus()

Quoted 86 lines · Harsh Prateek Bora,
Quoted 82 lines · Cédric Le Goater,
Quoted 8 lines · Harsh Prateek Bora
Quoted 5 lines · Cédric Le Goater

Introduce a helper routine defining one CPU device node to fix this warning :

../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a

previous local [-Wshadow=compatible-local]

Quoted 11 lines
Quoted 11 lines
     812 |         CPUState *cs = rev[i];
         |                   ^~
   ../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
     786 |     CPUState *cs;
         |               ^~
---
  hw/ppc/spapr.c | 36 +++++++++++++++++++++---------------
  1 file changed, 21 insertions(+), 15 deletions(-)
Quoted 5 lines

hw/ppc/spapr.c static void spapr_dt_cpu(CPUState *cs, void *fdt,

Quoted 5 lines
hw/ppc/spapr.c +0 -0
index de3c616b4637..d89f0fd496b6 100644
@@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt,

int offset,

Quoted 3 lines

hw/ppc/spapr.c static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,

Quoted 3 lines
hw/ppc/spapr.c +1 -0
                                pcc->lrg_decr_bits)));
  }
+static void spapr_dt_one_cpu(void *fdt, SpaprMachineState *spapr,

CPUState *cs,

Quoted 15 lines
Quoted 15 lines
hw/ppc/spapr.c +15 -0
+                             int cpus_offset)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    int index = spapr_get_vcpu_id(cpu);
+    DeviceClass *dc = DEVICE_GET_CLASS(cs);
+    g_autofree char *nodename = NULL;
+    int offset;
+
+    if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
+        return;
+    }
+
+    nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
+    offset = fdt_add_subnode(fdt, cpus_offset, nodename);
+    _FDT(offset);
Quoted 8 lines

hw/ppc/spapr.c static void spapr_dt_cpus(void *fdt,

Quoted 8 lines
hw/ppc/spapr.c +4 -0
+    spapr_dt_cpu(cs, fdt, offset, spapr);
+}
+
+
  static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
  {
      CPUState **rev;
@@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt,

SpaprMachineState *spapr)

Quoted 14 lines
Quoted 14 lines
hw/ppc/spapr.c +0 -12
      }
      for (i = n_cpus - 1; i >= 0; i--) {
-        CPUState *cs = rev[i];
-        PowerPCCPU *cpu = POWERPC_CPU(cs);
-        int index = spapr_get_vcpu_id(cpu);
-        DeviceClass *dc = DEVICE_GET_CLASS(cs);
-        g_autofree char *nodename = NULL;
-        int offset;
-
-        if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
-            continue;
-        }
-
-        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
Quoted 8 lines

hw/ppc/spapr.c static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr) · line 832

Quoted 4 lines
hw/ppc/spapr.c +1 -3
-        offset = fdt_add_subnode(fdt, cpus_offset, nodename);
-        _FDT(offset);
-        spapr_dt_cpu(cs, fdt, offset, spapr);
+        spapr_dt_one_cpu(fdt, spapr, rev[i], cpus_offset);

Do we want to replace the call to spapr_dt_cpu in spapr_core_dt_populate() with the _one_ as well?
Not sure about the implication of additional instructions there.

yeah may be we could rework spapr_dt_one_cpu() and spapr_core_dt_populate()
in a single routine. They are similar. It can come later.

Quoted 9 lines
Quoted 6 lines
Quoted 1 line

Also, could this code insider wrapper become part of spapr_dt_cpu()

itself?

Quoted 1 line

If can't, do we want a better renaming of wrapper here?

I am open to proposal :)

How about spapr_dt_cpu_prepare() ?

I guess spapr_dt_cpu_process() may be more apt since it calls the spapr_dt_cpu internally.

Quoted 15 lines
Quoted 15 lines

Thanks

C.

Quoted 6 lines

Otherwise,

Quoted 2 lines
hw/ppc/spapr.c +0 -0
      }
      g_free(rev);
#13 lore raw

Re: [PATCH 3/8] spapr: Clean up local variable shadowing in spapr_dt_cpus()

Quoted 94 lines · Harsh Prateek Bora

On Tue, 19 Sept, 2023, 6:34 pm Harsh Prateek Bora, <[email protected] <mailto:[email protected]>> wrote:

    On Tue, 19 Sept, 2023, 4:37 pm Cédric Le Goater, <[email protected] <mailto:[email protected]>> wrote:

        On 9/19/23 09:28, Harsh Prateek Bora wrote:
         >
         >
         > On 9/18/23 20:28, Cédric Le Goater wrote:
         >> Introduce a helper routine defining one CPU device node to fix this
         >> warning :
         >>
         >>    ../hw/ppc/spapr.c: In function ‘spapr_dt_cpus’:
         >>    ../hw/ppc/spapr.c:812:19: warning: declaration of ‘cs’ shadows a previous local [-Wshadow=compatible-local]
         >>      812 |         CPUState *cs = rev[i];
         >>          |                   ^~
         >>    ../hw/ppc/spapr.c:786:15: note: shadowed declaration is here
         >>      786 |     CPUState *cs;
         >>          |               ^~
         >>
         >> Signed-off-by: Cédric Le Goater <[email protected] <mailto:[email protected]>>
         >> ---
         >>   hw/ppc/spapr.c | 36 +++++++++++++++++++++---------------
         >>   1 file changed, 21 insertions(+), 15 deletions(-)
         >>
         >> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
         >> index de3c616b4637..d89f0fd496b6 100644
         >> --- a/hw/ppc/spapr.c
         >> +++ b/hw/ppc/spapr.c
         >> @@ -780,6 +780,26 @@ static void spapr_dt_cpu(CPUState *cs, void *fdt, int offset,
         >>                                 pcc->lrg_decr_bits)));
         >>   }
         >> +static void spapr_dt_one_cpu(void *fdt, SpaprMachineState *spapr, CPUState *cs,
         >> +                             int cpus_offset)
         >> +{
         >> +    PowerPCCPU *cpu = POWERPC_CPU(cs);
         >> +    int index = spapr_get_vcpu_id(cpu);
         >> +    DeviceClass *dc = DEVICE_GET_CLASS(cs);
         >> +    g_autofree char *nodename = NULL;
         >> +    int offset;
         >> +
         >> +    if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
         >> +        return;
         >> +    }
         >> +
         >> +    nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
         >> +    offset = fdt_add_subnode(fdt, cpus_offset, nodename);
         >> +    _FDT(offset);
         >> +    spapr_dt_cpu(cs, fdt, offset, spapr);
         >> +}
         >> +
         >> +
         >>   static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
         >>   {
         >>       CPUState **rev;
         >> @@ -809,21 +829,7 @@ static void spapr_dt_cpus(void *fdt, SpaprMachineState *spapr)
         >>       }
         >>       for (i = n_cpus - 1; i >= 0; i--) {
         >> -        CPUState *cs = rev[i];
         >> -        PowerPCCPU *cpu = POWERPC_CPU(cs);
         >> -        int index = spapr_get_vcpu_id(cpu);
         >> -        DeviceClass *dc = DEVICE_GET_CLASS(cs);
         >> -        g_autofree char *nodename = NULL;
         >> -        int offset;
         >> -
         >> -        if (!spapr_is_thread0_in_vcore(spapr, cpu)) {
         >> -            continue;
         >> -        }
         >> -
         >> -        nodename = g_strdup_printf("%s@%x", dc->fw_name, index);
         >> -        offset = fdt_add_subnode(fdt, cpus_offset, nodename);
         >> -        _FDT(offset);
         >> -        spapr_dt_cpu(cs, fdt, offset, spapr);
         >> +        spapr_dt_one_cpu(fdt, spapr, rev[i], cpus_offset);
         >
         > Do we want to replace the call to spapr_dt_cpu in
         > spapr_core_dt_populate() with the _one_ as well?
         > Not sure about the implication of additional instructions there.

        yeah may be we could rework spapr_dt_one_cpu() and spapr_core_dt_populate()
        in a single routine. They are similar. It can come later.

         > Also, could this code insider wrapper become part of spapr_dt_cpu() itself?
         > If can't, do we want a better renaming of wrapper here?

        I am open to proposal :)


    How about spapr_dt_cpu_prepare() ?
Quoted 1 line

I guess spapr_dt_cpu_process() may be more apt since it calls the spapr_dt_cpu internally.

*_one_* is a common qualifier in QEMU and Linux routine names.

C.

Quoted 16 lines


        Thanks

        C.


         >
         > Otherwise,
         > Reviewed-by: Harsh Prateek Bora <[email protected] <mailto:[email protected]>>
         >
         >>       }
         >>       g_free(rev);
#14 lore raw

PATCH 4/8 spapr: Clean up local variable shadowing in spapr_init_cpus()

In reply to Cédric Le Goater

Remove extra 'i' variable to fix this warning :

../hw/ppc/spapr.c: In function ‘spapr_init_cpus’:
../hw/ppc/spapr.c:2668:13: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]
2668 | int i;
| ^
../hw/ppc/spapr.c:2645:9: note: shadowed declaration is here
2645 | int i;
| ^

---
 hw/ppc/spapr.c | 2 --
 1 file changed, 2 deletions(-)
hw/ppc/spapr.c +0 -2
index d89f0fd496b6..41ce7de77c14 100644
@@ -2665,8 +2665,6 @@ static void spapr_init_cpus(SpaprMachineState *spapr)
     }
 
     if (smc->pre_2_10_has_unused_icps) {
-        int i;
-
         for (i = 0; i < spapr_max_server_number(spapr); i++) {
             /* Dummy entries get deregistered when real ICPState objects
              * are registered during CPU core hotplug.
Signature · 1 line
2.41.0
Reviewed-by on v1 4/8
#15 lore raw

Re: [PATCH 4/8] spapr: Clean up local variable shadowing in spapr_init_cpus()

Quoted 11 lines · Cédric Le Goater

Remove extra 'i' variable to fix this warning :

../hw/ppc/spapr.c: In function ‘spapr_init_cpus’:
../hw/ppc/spapr.c:2668:13: warning: declaration of ‘i’ shadows a previous local [-Wshadow=compatible-local]

    2668 |         int i;
         |             ^
   ../hw/ppc/spapr.c:2645:9: note: shadowed declaration is here
    2645 |     int i;
         |         ^
Quoted 17 lines
---
  hw/ppc/spapr.c | 2 --
  1 file changed, 2 deletions(-)
hw/ppc/spapr.c +0 -2
index d89f0fd496b6..41ce7de77c14 100644
@@ -2665,8 +2665,6 @@ static void spapr_init_cpus(SpaprMachineState *spapr)
      }
 
      if (smc->pre_2_10_has_unused_icps) {
-        int i;
-
          for (i = 0; i < spapr_max_server_number(spapr); i++) {
              /* Dummy entries get deregistered when real ICPState objects
               * are registered during CPU core hotplug.
#16 lore raw

PATCH 5/8 spapr: Clean up local variable shadowing in spapr_get_fw_dev_path()

In reply to Cédric Le Goater

Rename PCIDevice variable to avoid this warning :

../hw/ppc/spapr.c: In function ‘spapr_get_fw_dev_path’:
../hw/ppc/spapr.c:3217:20: warning: declaration of ‘pcidev’ shadows a previous local [-Wshadow=compatible-local]

   3217 |         PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
        |                    ^~~~~~
  ../hw/ppc/spapr.c:3147:16: note: shadowed declaration is here
   3147 |     PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
        |                ^~~~~~
---
 hw/ppc/spapr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +2 -2
index 41ce7de77c14..8090fb0302df 100644
@@ -3214,8 +3214,8 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
 
     if (g_str_equal("pci-bridge", qdev_fw_name(dev))) {
         /* SLOF uses "pci" instead of "pci-bridge" for PCI bridges */
-        PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
-        return g_strdup_printf("pci@%x", PCI_SLOT(pcidev->devfn));
+        PCIDevice *pdev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
+        return g_strdup_printf("pci@%x", PCI_SLOT(pdev->devfn));
     }
 
     if (pcidev) {
Signature · 1 line
2.41.0
Reviewed-by on v1 5/8
#17 lore raw

Re: [PATCH 5/8] spapr: Clean up local variable shadowing in spapr_get_fw_dev_path()

Quoted 10 lines · Cédric Le Goater

Rename PCIDevice variable to avoid this warning :

   ../hw/ppc/spapr.c: In function ‘spapr_get_fw_dev_path’:
   ../hw/ppc/spapr.c:3217:20: warning: declaration of ‘pcidev’ shadows a previous local [-Wshadow=compatible-local]
    3217 |         PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
         |                    ^~~~~~
   ../hw/ppc/spapr.c:3147:16: note: shadowed declaration is here
    3147 |     PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
         |                ^~~~~~
Quoted 4 lines
---
  hw/ppc/spapr.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
#18 lore raw

Re: [PATCH 5/8] spapr: Clean up local variable shadowing in spapr_get_fw_dev_path()

In reply to Cédric Le Goater
Quoted 20 lines · Cédric Le Goater

Rename PCIDevice variable to avoid this warning :

   ../hw/ppc/spapr.c: In function ‘spapr_get_fw_dev_path’:
   ../hw/ppc/spapr.c:3217:20: warning: declaration of ‘pcidev’ shadows a previous local [-Wshadow=compatible-local]
    3217 |         PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
         |                    ^~~~~~
   ../hw/ppc/spapr.c:3147:16: note: shadowed declaration is here
    3147 |     PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
         |                ^~~~~~
---
  hw/ppc/spapr.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +0 -0
index 41ce7de77c14..8090fb0302df 100644

hw/ppc/spapr.c static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus, · line 3218

Quoted 7 lines
hw/ppc/spapr.c +2 -2
@@ -3214,8 +3214,8 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
 
      if (g_str_equal("pci-bridge", qdev_fw_name(dev))) {
          /* SLOF uses "pci" instead of "pci-bridge" for PCI bridges */
-        PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
-        return g_strdup_printf("pci@%x", PCI_SLOT(pcidev->devfn));
+        PCIDevice *pdev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
+        return g_strdup_printf("pci@%x", PCI_SLOT(pdev->devfn));

Instead of renaming, can't we use pcidev itself without re-declaring ?

Quoted 3 lines
hw/ppc/spapr.c +0 -0
      }
 
      if (pcidev) {
#19 lore raw

Re: [PATCH 5/8] spapr: Clean up local variable shadowing in spapr_get_fw_dev_path()

Quoted 18 lines · Harsh Prateek Bora
Quoted 15 lines · Cédric Le Goater

Rename PCIDevice variable to avoid this warning :

   ../hw/ppc/spapr.c: In function ‘spapr_get_fw_dev_path’:
   ../hw/ppc/spapr.c:3217:20: warning: declaration of ‘pcidev’ shadows a previous local [-Wshadow=compatible-local] 3217 |         PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
         |                    ^~~~~~
   ../hw/ppc/spapr.c:3147:16: note: shadowed declaration is here
    3147 |     PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
         |                ^~~~~~

---
  hw/ppc/spapr.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 13 lines

hw/ppc/spapr.c static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus, · line 3217

Quoted 11 lines
hw/ppc/spapr.c +2 -2
index 41ce7de77c14..8090fb0302df 100644
@@ -3214,8 +3214,8 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
       if (g_str_equal("pci-bridge", qdev_fw_name(dev))) {
           /* SLOF uses "pci" instead of "pci-bridge" for PCI bridges */
-        PCIDevice *pcidev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
-        return g_strdup_printf("pci@%x", PCI_SLOT(pcidev->devfn));
+        PCIDevice *pdev = CAST(PCIDevice, dev, TYPE_PCI_DEVICE);
+        return g_strdup_printf("pci@%x", PCI_SLOT(pdev->devfn));

Instead of renaming, can't we use pcidev itself without re-declaring ?

I agree this could be done. But there is this test below :

Quoted 3 lines

hw/ppc/spapr.c static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus, · line 3221

Quoted 3 lines
hw/ppc/spapr.c +0 -0
       }
       if (pcidev) {

which makes use of the same variable. I would rather keep the same logic in the code or rewrite the routine completely with something like:

    if (object_dynamic_cast(OBJECT(dev), TYPE_1 {
        /* return this */
    } else if (object_dynamic_cast(OBJECT(dev), TYPE_2 {
        /* or that */
    } else if (object_dynamic_cast(OBJECT(dev), "some string"))
    ....
    } else {
        error_report("...");
    }

    return NULL;

This is beyond the issue that this patch is trying to fix.

Thanks,

C.

#20 lore raw

PATCH 6/8 spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()

In reply to Cédric Le Goater

Remove extra 'drc_index' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:
../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’ shadows a previous local [-Wshadow=compatible-local]

   1240 |                 uint32_t drc_index = spapr_drc_index(drc);
        |                          ^~~~~~~~~
  ../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
   1155 |     uint32_t drc_index;
        |              ^~~~~~~~~
---
 hw/ppc/spapr_drc.c | 2 --
 1 file changed, 2 deletions(-)
hw/ppc/spapr_drc.c +0 -2
index b5c400a94d1c..843e318312d3 100644
@@ -1237,8 +1237,6 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
         case FDT_END_NODE:
             drc->ccs_depth--;
             if (drc->ccs_depth == 0) {
-                uint32_t drc_index = spapr_drc_index(drc);
-
                 /* done sending the device tree, move to configured state */
                 trace_spapr_drc_set_configured(drc_index);
                 drc->state = drck->ready_state;
Signature · 1 line
2.41.0
#21 lore raw

Re: [PATCH 6/8] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()

Quoted 20 lines · Cédric Le Goater

Remove extra 'drc_index' variable to avoid this warning :

   ../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:
   ../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’ shadows a previous local [-Wshadow=compatible-local]
    1240 |                 uint32_t drc_index = spapr_drc_index(drc);
         |                          ^~~~~~~~~
   ../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
    1155 |     uint32_t drc_index;
         |              ^~~~~~~~~
---
  hw/ppc/spapr_drc.c | 2 --
  1 file changed, 2 deletions(-)
hw/ppc/spapr_drc.c +0 -0
index b5c400a94d1c..843e318312d3 100644

hw/ppc/spapr_drc.c static void rtas_ibm_configure_connector(PowerPCCPU *cpu, · line 1241

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -2
@@ -1237,8 +1237,6 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
          case FDT_END_NODE:
              drc->ccs_depth--;
              if (drc->ccs_depth == 0) {
-                uint32_t drc_index = spapr_drc_index(drc);
-

I guess you only wanted to remove re-declaration part. Assigning the value returned by this function doesnt seem to happen before.

Quoted 3 lines
hw/ppc/spapr_drc.c +0 -0
                  /* done sending the device tree, move to configured state */
                  trace_spapr_drc_set_configured(drc_index);
                  drc->state = drck->ready_state;
#22 lore raw

Re: [PATCH 6/8] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()

Quoted 18 lines · Harsh Prateek Bora
Quoted 15 lines · Cédric Le Goater

Remove extra 'drc_index' variable to avoid this warning :

   ../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:
   ../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’ shadows a previous local [-Wshadow=compatible-local] 1240 |                 uint32_t drc_index = spapr_drc_index(drc);
         |                          ^~~~~~~~~
   ../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
    1155 |     uint32_t drc_index;
         |              ^~~~~~~~~

---
  hw/ppc/spapr_drc.c | 2 --

  1 file changed, 2 deletions(-)
Quoted 11 lines
Quoted 10 lines
hw/ppc/spapr_drc.c +0 -0
index b5c400a94d1c..843e318312d3 100644
@@ -1237,8 +1237,6 @@ static void rtas_ibm_configure_connector(PowerPCCPU *cpu,

          case FDT_END_NODE:
              drc->ccs_depth--;
              if (drc->ccs_depth == 0) {
-                uint32_t drc_index = spapr_drc_index(drc); -

I guess you only wanted to remove re-declaration part. Assigning the value returned by this function doesnt seem to happen before.

drc_index is assigned at the top of this large routine with :

    drc_index = rtas_ld(wa_addr, 0);
    drc = spapr_drc_by_index(drc_index);

So, the extra local variable 'drc_index' is simply redundant because there are no reason for it to change. The drc object is the same AFAICT. Correct ? I should have explained that better in the commit log.

Thanks,

C.

Quoted 4 lines
Quoted 4 lines

                  /* done sending the device tree, move to configured state */ trace_spapr_drc_set_configured(drc_index); drc->state = drck->ready_state;

#23 lore raw

Re: [PATCH 6/8] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()

Quoted 36 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Remove extra 'drc_index' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:

   ../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’

shadows a previous local [-Wshadow=compatible-local]

Quoted 11 lines
Quoted 11 lines
    1240 |                 uint32_t drc_index = spapr_drc_index(drc);
         |                          ^~~~~~~~~
   ../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
    1155 |     uint32_t drc_index;
         |              ^~~~~~~~~
---
  hw/ppc/spapr_drc.c | 2 --
  1 file changed, 2 deletions(-)
Quoted 5 lines

hw/ppc/spapr_drc.c static void

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -0
index b5c400a94d1c..843e318312d3 100644
@@ -1237,8 +1237,6 @@ static void

rtas_ibm_configure_connector(PowerPCCPU *cpu,

Quoted 6 lines

hw/ppc/spapr_drc.c static void rtas_ibm_configure_connector(PowerPCCPU *cpu, · line 1241

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -2
          case FDT_END_NODE:
              drc->ccs_depth--;
              if (drc->ccs_depth == 0) {
-                uint32_t drc_index = spapr_drc_index(drc);
-

I guess you only wanted to remove re-declaration part. Assigning the

value returned by this function doesnt seem to happen before.

drc_index is assigned at the top of this large routine with :

Quoted 8 lines
     drc_index = rtas_ld(wa_addr, 0);
     drc = spapr_drc_by_index(drc_index);

So, the extra local variable 'drc_index' is simply redundant because there are no reason for it to change. The drc object is the same AFAICT. Correct ? I should have explained that better in the commit log.

Okay, since both routines were implemented differently, I wasn't sure about the impact of reassignment. Better commit log is always welcome.

Regards
Harsh

Thanks,

Quoted 12 lines

C.

Quoted 2 lines

hw/ppc/spapr_drc.c static void · line 1240

Quoted 2 lines
hw/ppc/spapr_drc.c +0 -0
                  /* done sending the device tree, move to configured

state */

Quoted 2 lines
Quoted 2 lines
hw/ppc/spapr_drc.c +0 -0
                  trace_spapr_drc_set_configured(drc_index);
                  drc->state = drck->ready_state;
#24 lore raw

Re: [PATCH 6/8] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()

Quoted 43 lines · Harsh Prateek Bora
Quoted 41 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Remove extra 'drc_index' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:

   ../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’

shadows a previous local [-Wshadow=compatible-local]

Quoted 11 lines
Quoted 11 lines
    1240 |                 uint32_t drc_index = spapr_drc_index(drc);
         |                          ^~~~~~~~~
   ../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
    1155 |     uint32_t drc_index;
         |              ^~~~~~~~~
---
  hw/ppc/spapr_drc.c | 2 --
  1 file changed, 2 deletions(-)
Quoted 5 lines

hw/ppc/spapr_drc.c static void

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -0
index b5c400a94d1c..843e318312d3 100644
@@ -1237,8 +1237,6 @@ static void

rtas_ibm_configure_connector(PowerPCCPU *cpu,

Quoted 6 lines

hw/ppc/spapr_drc.c static void rtas_ibm_configure_connector(PowerPCCPU *cpu, · line 1241

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -2
          case FDT_END_NODE:
              drc->ccs_depth--;
              if (drc->ccs_depth == 0) {
-                uint32_t drc_index = spapr_drc_index(drc);
-

I guess you only wanted to remove re-declaration part. Assigning the

value returned by this function doesnt seem to happen before.

drc_index is assigned at the top of this large routine with :

     drc_index = rtas_ld(wa_addr, 0);
     drc = spapr_drc_by_index(drc_index);
Quoted 7 lines
Quoted 4 lines

So, the extra local variable 'drc_index' is simply redundant because there are no reason for it to change. The drc object is the same AFAICT. Correct ? I should have explained that better in the commit log.

Okay, since both routines were implemented differently, I wasn't sure about the impact of reassignment. Better commit log is always welcome.

Do you expect a respin? If not, would you like to give your R-by?

Reviewed-by
#25 lore raw

Re: [PATCH 6/8] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector()

Quoted 50 lines · Markus Armbruster
Quoted 48 lines · Harsh Prateek Bora
Quoted 45 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Remove extra 'drc_index' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘rtas_ibm_configure_connector’:
../hw/ppc/spapr_drc.c:1240:26: warning: declaration of ‘drc_index’

shadows a previous local [-Wshadow=compatible-local]

Quoted 11 lines
Quoted 11 lines
     1240 |                 uint32_t drc_index = spapr_drc_index(drc);
          |                          ^~~~~~~~~
    ../hw/ppc/spapr_drc.c:1155:14: note: shadowed declaration is here
     1155 |     uint32_t drc_index;
          |              ^~~~~~~~~
---
   hw/ppc/spapr_drc.c | 2 --
   1 file changed, 2 deletions(-)
Quoted 5 lines

hw/ppc/spapr_drc.c static void

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -0
index b5c400a94d1c..843e318312d3 100644
@@ -1237,8 +1237,6 @@ static void

rtas_ibm_configure_connector(PowerPCCPU *cpu,

Quoted 6 lines

hw/ppc/spapr_drc.c static void rtas_ibm_configure_connector(PowerPCCPU *cpu, · line 1241

Quoted 5 lines
hw/ppc/spapr_drc.c +0 -2
           case FDT_END_NODE:
               drc->ccs_depth--;
               if (drc->ccs_depth == 0) {
-                uint32_t drc_index = spapr_drc_index(drc);
-

I guess you only wanted to remove re-declaration part. Assigning the

value returned by this function doesnt seem to happen before.

drc_index is assigned at the top of this large routine with :

      drc_index = rtas_ld(wa_addr, 0);
      drc = spapr_drc_by_index(drc_index);

So, the extra local variable 'drc_index' is simply redundant because there are no reason for it to change. The drc object is the same AFAICT. Correct ? I should have explained that better in the commit log.

Quoted 5 lines
Quoted 2 lines

Okay, since both routines were implemented differently, I wasn't sure about the impact of reassignment. Better commit log is always welcome.

Do you expect a respin? If not, would you like to give your R-by?

Oh sure,

#26 lore raw

PATCH 7/8 spapr/pci: Clean up local variable shadowing in spapr_phb_realize()

In reply to Cédric Le Goater

Rename SysBusDevice variable to avoid this warning :

../hw/ppc/spapr_pci.c: In function ‘spapr_phb_realize’:
../hw/ppc/spapr_pci.c:1872:24: warning: declaration of ‘s’ shadows a previous local [-Wshadow=local]
1872 | SpaprPhbState *s;
| ^
../hw/ppc/spapr_pci.c:1829:19: note: shadowed declaration is here
1829 | SysBusDevice *s = SYS_BUS_DEVICE(dev);
| ^

---
 hw/ppc/spapr_pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +3 -3
index ce1495931744..370c5a90f218 100644
@@ -1826,9 +1826,9 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
         (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(),
                                                   TYPE_SPAPR_MACHINE);
     SpaprMachineClass *smc = spapr ? SPAPR_MACHINE_GET_CLASS(spapr) : NULL;
-    SysBusDevice *s = SYS_BUS_DEVICE(dev);
-    SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
-    PCIHostState *phb = PCI_HOST_BRIDGE(s);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(sbd);
+    PCIHostState *phb = PCI_HOST_BRIDGE(sbd);
     MachineState *ms = MACHINE(spapr);
     char *namebuf;
     int i;
Signature · 1 line
2.41.0
Reviewed-by on v1 7/8
#27 lore raw

Re: [PATCH 7/8] spapr/pci: Clean up local variable shadowing in spapr_phb_realize()

Quoted 20 lines · Cédric Le Goater

Rename SysBusDevice variable to avoid this warning :

../hw/ppc/spapr_pci.c: In function ‘spapr_phb_realize’:
../hw/ppc/spapr_pci.c:1872:24: warning: declaration of ‘s’ shadows a previous local [-Wshadow=local]

    1872 |         SpaprPhbState *s;
         |                        ^
   ../hw/ppc/spapr_pci.c:1829:19: note: shadowed declaration is here
    1829 |     SysBusDevice *s = SYS_BUS_DEVICE(dev);
         |                   ^
---
  hw/ppc/spapr_pci.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
hw/ppc/spapr_pci.c +0 -0
index ce1495931744..370c5a90f218 100644

hw/ppc/spapr_pci.c static void spapr_phb_realize(DeviceState *dev, Error **errp) · line 1830

Quoted 8 lines
hw/ppc/spapr_pci.c +2 -3
@@ -1826,9 +1826,9 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
          (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(),
                                                    TYPE_SPAPR_MACHINE);
      SpaprMachineClass *smc = spapr ? SPAPR_MACHINE_GET_CLASS(spapr) : NULL;
-    SysBusDevice *s = SYS_BUS_DEVICE(dev);
-    SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
-    PCIHostState *phb = PCI_HOST_BRIDGE(s);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(sbd);

Declaration of SpaprPhbState *s later in the code could be brought here?

Quoted 4 lines
hw/ppc/spapr_pci.c +1 -0
+    PCIHostState *phb = PCI_HOST_BRIDGE(sbd);
      MachineState *ms = MACHINE(spapr);
      char *namebuf;
      int i;
#28 lore raw

Re: [PATCH 7/8] spapr/pci: Clean up local variable shadowing in spapr_phb_realize()

Quoted 18 lines · Harsh Prateek Bora
Quoted 15 lines · Cédric Le Goater

Rename SysBusDevice variable to avoid this warning :

   ../hw/ppc/spapr_pci.c: In function ‘spapr_phb_realize’:
   ../hw/ppc/spapr_pci.c:1872:24: warning: declaration of ‘s’ shadows a previous local [-Wshadow=local] 1872 |         SpaprPhbState *s;
         |                        ^
   ../hw/ppc/spapr_pci.c:1829:19: note: shadowed declaration is here
    1829 |     SysBusDevice *s = SYS_BUS_DEVICE(dev);
         |                   ^

---
  hw/ppc/spapr_pci.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines

hw/ppc/spapr_pci.c static void spapr_phb_realize(DeviceState *dev, Error **errp) · line 1830

Quoted 13 lines
hw/ppc/spapr_pci.c +2 -3
index ce1495931744..370c5a90f218 100644
@@ -1826,9 +1826,9 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
           (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(),
                                                     TYPE_SPAPR_MACHINE);
       SpaprMachineClass *smc = spapr ? SPAPR_MACHINE_GET_CLASS(spapr) : NULL;
-    SysBusDevice *s = SYS_BUS_DEVICE(dev);
-    SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
-    PCIHostState *phb = PCI_HOST_BRIDGE(s);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(sbd);

Declaration of SpaprPhbState *s later in the code could be brought here?

nah. 's' is really local. It could be even called 'tmp' IMO.

Thanks,

C.

Quoted 7 lines
Quoted 4 lines
hw/ppc/spapr_pci.c +1 -0
+    PCIHostState *phb = PCI_HOST_BRIDGE(sbd);
       MachineState *ms = MACHINE(spapr);
       char *namebuf;
       int i;
#29 lore raw

PATCH 8/8 spapr/drc: Clean up local variable shadowing in prop_get_fdt()

In reply to Cédric Le Goater

Rename 'name' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows a parameter [-Wshadow=compatible-local]

    344 |         const char *name = NULL;
        |                     ^~~~

../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
| ~~~~~~~~~~~~^~~~

---
 hw/ppc/spapr_drc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +5 -5
index 843e318312d3..2b99d3b4b1a6 100644
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
     fdt_depth = 0;
 
     do {
-        const char *name = NULL;
+        const char *dt_name = NULL;
         const struct fdt_property *prop = NULL;
         int prop_len = 0, name_len = 0;
         uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
         switch (tag) {
         case FDT_BEGIN_NODE:
             fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len);
-            if (!visit_start_struct(v, name, NULL, 0, errp)) {
+            dt_name = fdt_get_name(fdt, fdt_offset, &name_len);
+            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) {
                 return;
             }
             break;
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
         case FDT_PROP: {
             int i;
             prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                 return;
             }
             for (i = 0; i < prop_len; i++) {
Signature · 1 line
2.41.0
Reviewed-by on v1 8/8
#30 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

Quoted 6 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows a parameter [-Wshadow=compatible-local]

     344 |         const char *name = NULL;
         |                     ^~~~
Quoted 8 lines

../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
| ~~~~~~~~~~~~^~~~

---
  hw/ppc/spapr_drc.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
#31 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

In reply to Cédric Le Goater
Quoted 20 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows a parameter [-Wshadow=compatible-local]

     344 |         const char *name = NULL;
         |                     ^~~~

../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
| ~~~~~~~~~~~~^~~~

---
  hw/ppc/spapr_drc.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +0 -0
index 843e318312d3..2b99d3b4b1a6 100644

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name, · line 344

Quoted 5 lines
hw/ppc/spapr_drc.c +1 -1
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
      fdt_depth = 0;
 
      do {
-        const char *name = NULL;
+        const char *dt_name = NULL;

I guess you wanted to use the input arg "name" here without re-declaration. I do not see "name" being used elsewhere in this routine.

regards,
Harsh

Quoted 25 lines
hw/ppc/spapr_drc.c +4 -4
          const struct fdt_property *prop = NULL;
          int prop_len = 0, name_len = 0;
          uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
          switch (tag) {
          case FDT_BEGIN_NODE:
              fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len);
-            if (!visit_start_struct(v, name, NULL, 0, errp)) {
+            dt_name = fdt_get_name(fdt, fdt_offset, &name_len);
+            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) {
                  return;
              }
              break;
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
          case FDT_PROP: {
              int i;
              prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                  return;
              }
              for (i = 0; i < prop_len; i++) {
#32 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

Quoted 18 lines · Harsh Prateek Bora
Quoted 15 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

   ../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
   ../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows a parameter [-Wshadow=compatible-local] 344 |         const char *name = NULL;
         |                     ^~~~
   ../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
     325 | static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
         |                                                   ~~~~~~~~~~~~^~~~

---
  hw/ppc/spapr_drc.c | 10 +++++-----

  1 file changed, 5 insertions(+), 5 deletions(-)
Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name, · line 343

Quoted 9 lines
hw/ppc/spapr_drc.c +1 -1
index 843e318312d3..2b99d3b4b1a6 100644
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
       fdt_depth = 0;
       do {
-        const char *name = NULL;
+        const char *dt_name = NULL;

I guess you wanted to use the input arg "name" here without re-declaration.

I don't understand. I don't want to use the input arg "name" here. It seems useless in this case.

C.

Quoted 29 lines

I do not see "name" being used elsewhere in this routine.

regards,
Harsh

Quoted 25 lines
hw/ppc/spapr_drc.c +0 -0
           const struct fdt_property *prop = NULL;
           int prop_len = 0, name_len = 0;
           uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
           switch (tag) {

          case FDT_BEGIN_NODE:
              fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len); -            if (!visit_start_struct(v, name, NULL, 0, errp)) { +            dt_name = fdt_get_name(fdt, fdt_offset, &name_len); +            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) { return;
              }
              break;

hw/ppc/spapr_drc.c +2 -2
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
           case FDT_PROP: {
               int i;
               prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                   return;
               }
               for (i = 0; i < prop_len; i++) {
#33 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

Quoted 33 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows

a parameter [-Wshadow=compatible-local]

Quoted 4 lines
Quoted 4 lines
     344 |         const char *name = NULL;
         |                     ^~~~

../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char

*name,

Quoted 1 line
Quoted 1 line
         |

~~~~~~~~~~~~^~~~

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
---
  hw/ppc/spapr_drc.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +0 -0
index 843e318312d3..2b99d3b4b1a6 100644
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 5 lines
Quoted 4 lines
hw/ppc/spapr_drc.c +1 -1
      fdt_depth = 0;
      do {
-        const char *name = NULL;
+        const char *dt_name = NULL;
Quoted 6 lines
Quoted 1 line

I guess you wanted to use the input arg "name" here without

re-declaration.

I don't understand. I don't want to use the input arg "name" here. It seems useless in this case.

Yeh, I realize now. This patch can actually remove the unused arg "name" as well?

C.

Quoted 36 lines
Quoted 9 lines

I do not see "name" being used elsewhere in this routine.

regards,
Harsh

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 4 lines
hw/ppc/spapr_drc.c +0 -0
          const struct fdt_property *prop = NULL;
          int prop_len = 0, name_len = 0;
          uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
hw/ppc/spapr_drc.c +2 -2
          switch (tag) {
          case FDT_BEGIN_NODE:
              fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len);
-            if (!visit_start_struct(v, name, NULL, 0, errp)) {
+            dt_name = fdt_get_name(fdt, fdt_offset, &name_len);
+            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) {
                  return;
              }
              break;
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 3 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name,

Quoted 3 lines
hw/ppc/spapr_drc.c +0 -0
          case FDT_PROP: {
              int i;
              prop = fdt_get_property_by_offset(fdt, fdt_offset,

&prop_len);

Quoted 7 lines
Quoted 7 lines
hw/ppc/spapr_drc.c +2 -2
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                  return;
              }
              for (i = 0; i < prop_len; i++) {
#34 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

Quoted 36 lines · Harsh Prateek Bora
Quoted 34 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows

a parameter [-Wshadow=compatible-local]

Quoted 4 lines
Quoted 4 lines
     344 |         const char *name = NULL;
         |                     ^~~~

../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char

*name,

Quoted 1 line
Quoted 1 line
         |

~~~~~~~~~~~~^~~~

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
---
  hw/ppc/spapr_drc.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +0 -0
index 843e318312d3..2b99d3b4b1a6 100644
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 6 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name, · line 344

Quoted 4 lines
hw/ppc/spapr_drc.c +1 -1
      fdt_depth = 0;
      do {
-        const char *name = NULL;
+        const char *dt_name = NULL;

I guess you wanted to use the input arg "name" here without

Quoted 8 lines
Quoted 5 lines

re-declaration.

I don't understand. I don't want to use the input arg "name" here. It seems useless in this case.

Yeh, I realize now. This patch can actually remove the unused arg "name" as well?

Cédric?

Lose ends like this one make me reluctant to queue a series, even when they look minor to me.

Quoted 34 lines
Quoted 34 lines

C.

Quoted 8 lines

I do not see "name" being used elsewhere in this routine.

regards,
Harsh

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 4 lines
hw/ppc/spapr_drc.c +0 -0
          const struct fdt_property *prop = NULL;
          int prop_len = 0, name_len = 0;
          uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
hw/ppc/spapr_drc.c +2 -2
          switch (tag) {
          case FDT_BEGIN_NODE:
              fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len);
-            if (!visit_start_struct(v, name, NULL, 0, errp)) {
+            dt_name = fdt_get_name(fdt, fdt_offset, &name_len);
+            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) {
                  return;
              }
              break;
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 3 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name,

Quoted 3 lines
hw/ppc/spapr_drc.c +0 -0
          case FDT_PROP: {
              int i;
              prop = fdt_get_property_by_offset(fdt, fdt_offset,

&prop_len);

Quoted 7 lines
Quoted 7 lines
hw/ppc/spapr_drc.c +2 -2
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                  return;
              }
              for (i = 0; i < prop_len; i++) {
#35 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

Quoted 44 lines · Markus Armbruster
Quoted 42 lines · Harsh Prateek Bora
Quoted 39 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows

a parameter [-Wshadow=compatible-local]

Quoted 4 lines
Quoted 4 lines

344 | const char *name = NULL;
| ^~~~
../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here
325 | static void prop_get_fdt(Object *obj, Visitor *v, const char

*name,

Quoted 1 line
Quoted 1 line
          |

~~~~~~~~~~~~^~~~

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
---
   hw/ppc/spapr_drc.c | 10 +++++-----
   1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +0 -0
index 843e318312d3..2b99d3b4b1a6 100644
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 6 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name, · line 344

Quoted 4 lines
hw/ppc/spapr_drc.c +1 -1
       fdt_depth = 0;
       do {
-        const char *name = NULL;
+        const char *dt_name = NULL;

I guess you wanted to use the input arg "name" here without

re-declaration.

I don't understand. I don't want to use the input arg "name" here. It seems useless in this case.

Quoted 7 lines
Quoted 2 lines

Yeh, I realize now. This patch can actually remove the unused arg "name" as well?

Cédric?

Lose ends like this one make me reluctant to queue a series, even when they look minor to me.

Unfortunately, we can not remove the unused arg "name" from the prototype. The routine is a ObjectPropertyAccessor argument of object_property_add().

Thanks,

C.

Quoted 36 lines
Quoted 35 lines
Quoted 35 lines

C.

Quoted 8 lines

I do not see "name" being used elsewhere in this routine.

regards,
Harsh

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 4 lines
hw/ppc/spapr_drc.c +0 -0
           const struct fdt_property *prop = NULL;
           int prop_len = 0, name_len = 0;
           uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
hw/ppc/spapr_drc.c +2 -2
           switch (tag) {
           case FDT_BEGIN_NODE:
               fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len);
-            if (!visit_start_struct(v, name, NULL, 0, errp)) {
+            dt_name = fdt_get_name(fdt, fdt_offset, &name_len);
+            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) {
                   return;
               }
               break;
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 3 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name,

Quoted 3 lines
hw/ppc/spapr_drc.c +0 -0
           case FDT_PROP: {
               int i;
               prop = fdt_get_property_by_offset(fdt, fdt_offset,

&prop_len);

Quoted 7 lines
Quoted 7 lines
hw/ppc/spapr_drc.c +2 -2
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                   return;
               }
               for (i = 0; i < prop_len; i++) {
Reviewed-by
#36 lore raw

Re: [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt()

Quoted 48 lines · Cédric Le Goater
Quoted 47 lines · Markus Armbruster
Quoted 44 lines · Harsh Prateek Bora
Quoted 33 lines · Cédric Le Goater,
Quoted 7 lines · Harsh Prateek Bora
Quoted 4 lines · Cédric Le Goater

Rename 'name' variable to avoid this warning :

    ../hw/ppc/spapr_drc.c: In function ‘prop_get_fdt’:
    ../hw/ppc/spapr_drc.c:344:21: warning: declaration of ‘name’ shadows

a parameter [-Wshadow=compatible-local]

Quoted 4 lines
Quoted 4 lines

      344 |         const char *name = NULL;
          |                     ^~~~ ../hw/ppc/spapr_drc.c:325:63: note: shadowed declaration is here 325 | static void prop_get_fdt(Object *obj, Visitor *v, const char

*name,

Quoted 1 line
Quoted 1 line

          |

~~~~~~~~~~~~^~~~

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines

---
   hw/ppc/spapr_drc.c | 10 +++++-----

   1 file changed, 5 insertions(+), 5 deletions(-)
hw/ppc/spapr_drc.c +0 -0
index 843e318312d3..2b99d3b4b1a6 100644
@@ -341,7 +341,7 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 5 lines
Quoted 4 lines
hw/ppc/spapr_drc.c +1 -1
        fdt_depth = 0;
        do {
-        const char *name = NULL;
+        const char *dt_name = NULL;
Quoted 6 lines
Quoted 1 line

I guess you wanted to use the input arg "name" here without

re-declaration.

I don't understand. I don't want to use the input arg "name" here. It seems useless in this case.

Yeh, I realize now. This patch can actually remove the unused arg "name" as well?

Quoted 8 lines
Quoted 4 lines

Cédric?

Lose ends like this one make me reluctant to queue a series, even when they look minor to me.

Unfortunately, we can not remove the unused arg "name" from the prototype. The routine is a ObjectPropertyAccessor argument of object_property_add().

Hmm, I see ..

Quoted 42 lines

Thanks,

C.

Quoted 36 lines
Quoted 35 lines
Quoted 35 lines

C.

Quoted 8 lines

I do not see "name" being used elsewhere in this routine.

regards,
Harsh

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 4 lines
hw/ppc/spapr_drc.c +0 -0
            const struct fdt_property *prop = NULL;
            int prop_len = 0, name_len = 0;
            uint32_t tag;
@@ -351,8 +351,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 11 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v,

Quoted 11 lines
hw/ppc/spapr_drc.c +0 -0
            switch (tag) {

           case FDT_BEGIN_NODE:
               fdt_depth++;
-            name = fdt_get_name(fdt, fdt_offset, &name_len); -            if (!visit_start_struct(v, name, NULL, 0, errp)) { +            dt_name = fdt_get_name(fdt, fdt_offset, &name_len); +            if (!visit_start_struct(v, dt_name, NULL, 0, errp)) { return;
               }
               break;

hw/ppc/spapr_drc.c +0 -0
@@ -369,8 +369,8 @@ static void prop_get_fdt(Object *obj, Visitor *v,

const char *name,

Quoted 3 lines

hw/ppc/spapr_drc.c static void prop_get_fdt(Object *obj, Visitor *v, const char *name,

Quoted 3 lines
hw/ppc/spapr_drc.c +0 -0
            case FDT_PROP: {
                int i;
                prop = fdt_get_property_by_offset(fdt, fdt_offset,

&prop_len);

Quoted 7 lines
Quoted 7 lines
hw/ppc/spapr_drc.c +2 -2
-            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
-            if (!visit_start_list(v, name, NULL, 0, errp)) {
+            dt_name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
+            if (!visit_start_list(v, dt_name, NULL, 0, errp)) {
                    return;
                }
                for (i = 0; i < prop_len; i++) {
#38 lore raw
Quoted 2 lines · Markus Armbruster

Looks like I forgot to notify you when I queued, my apologies. Series has since been merged.

Perfect !

C.