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

Cédric Le Goater posted 8 patches 5 months, 1 week ago
Maintainers: "Cédric Le Goater" <clg@kaod.org>, Nicholas Piggin <npiggin@gmail.com>, "Frédéric Barrat" <fbarrat@linux.ibm.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Harsh Prateek Bora <harshpb@linux.ibm.com>
[PATCH 7/8] spapr/pci: Clean up local variable shadowing in spapr_phb_realize()
Posted by Cédric Le Goater 5 months, 1 week ago
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);
        |                   ^

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/ppc/spapr_pci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index ce1495931744..370c5a90f218 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -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;
-- 
2.41.0


Re: [PATCH 7/8] spapr/pci: Clean up local variable shadowing in spapr_phb_realize()
Posted by Harsh Prateek Bora 5 months, 1 week ago

On 9/18/23 20:28, Cédric Le Goater wrote:
> 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);
>          |                   ^
> 
> Signed-off-by: Cédric Le Goater <clg@kaod.org>
> ---
>   hw/ppc/spapr_pci.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index ce1495931744..370c5a90f218 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -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?

Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>

> +    PCIHostState *phb = PCI_HOST_BRIDGE(sbd);
>       MachineState *ms = MACHINE(spapr);
>       char *namebuf;
>       int i;

Re: [PATCH 7/8] spapr/pci: Clean up local variable shadowing in spapr_phb_realize()
Posted by Cédric Le Goater 5 months, 1 week ago
On 9/19/23 10:38, Harsh Prateek Bora wrote:
> 
> 
> On 9/18/23 20:28, Cédric Le Goater wrote:
>> 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);
>>          |                   ^
>>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> ---
>>   hw/ppc/spapr_pci.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
>> index ce1495931744..370c5a90f218 100644
>> --- a/hw/ppc/spapr_pci.c
>> +++ b/hw/ppc/spapr_pci.c
>> @@ -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.


> 
> Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
> 
>> +    PCIHostState *phb = PCI_HOST_BRIDGE(sbd);
>>       MachineState *ms = MACHINE(spapr);
>>       char *namebuf;
>>       int i;