Skip to contentSkip to conversation

aspeed: Clean up local variable shadowing

PATCH Applied Cédric Le Goater 5 participants 19 messages Sep 22, 2023 – Sep 29, 2023 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

cover aspeed: Clean up local variable shadowing

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Could you please double check patch 4 ?

Thanks,

C.

Cédric Le Goater (4):
aspeed/i2c: Clean up local variable shadowing
aspeed: Clean up local variable shadowing
aspeed/i3c: Rename variable shadowing a local
aspeed/timer: Clean up local variable shadowing

 hw/arm/aspeed_ast2600.c | 10 +++++-----
 hw/i2c/aspeed_i2c.c     |  1 -
 hw/misc/aspeed_i3c.c    |  6 +++---
 hw/timer/aspeed_timer.c |  2 +-
 4 files changed, 9 insertions(+), 10 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/4 aspeed/i2c: Clean up local variable shadowing

Remove superfluous local 'data' variable and use the one define at the top of the routine. This fixes :

../hw/i2c/aspeed_i2c.c: In function ‘aspeed_i2c_bus_recv’:
../hw/i2c/aspeed_i2c.c:315:17: warning: declaration of ‘data’ shadows a previous local [-Wshadow=compatible-local]

    315 |         uint8_t data;
        |                 ^~~~
  ../hw/i2c/aspeed_i2c.c:288:13: note: shadowed declaration is here
    288 |     uint8_t data;
        |             ^~~~
---
 hw/i2c/aspeed_i2c.c | 1 -
 1 file changed, 1 deletion(-)
hw/i2c/aspeed_i2c.c +0 -1
index 7275d40749a9..1037c22b2f79 100644
@@ -312,7 +312,6 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)
         SHARED_ARRAY_FIELD_DP32(bus->regs, reg_pool_ctrl, RX_COUNT, i & 0xff);
         SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_BUFF_EN, 0);
     } else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN)) {
-        uint8_t data;
         /* In new mode, clear how many bytes we RXed */
         if (aspeed_i2c_is_new_mode(bus->controller)) {
             ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
Signature · 1 line
2.41.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] aspeed/i2c: Clean up local variable shadowing

Quoted 11 lines · Cédric Le Goater

Remove superfluous local 'data' variable and use the one define at the top of the routine. This fixes :

../hw/i2c/aspeed_i2c.c: In function ‘aspeed_i2c_bus_recv’:

   ../hw/i2c/aspeed_i2c.c:315:17: warning: declaration of ‘data’ shadows a previous local [-Wshadow=compatible-local]
     315 |         uint8_t data;
         |                 ^~~~
   ../hw/i2c/aspeed_i2c.c:288:13: note: shadowed declaration is here
     288 |     uint8_t data;
         |             ^~~~
Quoted 4 lines
---
  hw/i2c/aspeed_i2c.c | 1 -
  1 file changed, 1 deletion(-)
maintainer Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] aspeed/i2c: Clean up local variable shadowing

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

Remove superfluous local 'data' variable and use the one define at the top of the routine. This fixes :

../hw/i2c/aspeed_i2c.c: In function ‘aspeed_i2c_bus_recv’:
../hw/i2c/aspeed_i2c.c:315:17: warning: declaration of ‘data’ shadows a previous local [-Wshadow=compatible-local]

Quoted 7 lines
    315 |         uint8_t data;
        |                 ^~~~
  ../hw/i2c/aspeed_i2c.c:288:13: note: shadowed declaration is here
    288 |     uint8_t data;
        |             ^~~~

messy.

Quoted 19 lines
---
 hw/i2c/aspeed_i2c.c | 1 -
 1 file changed, 1 deletion(-)
hw/i2c/aspeed_i2c.c +0 -2
index 7275d40749a9..1037c22b2f79 100644
@@ -312,7 +312,6 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)
         SHARED_ARRAY_FIELD_DP32(bus->regs, reg_pool_ctrl, RX_COUNT, i & 0xff);
         SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_BUFF_EN, 0);
     } else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN)) {
-        uint8_t data;
         /* In new mode, clear how many bytes we RXed */
         if (aspeed_i2c_is_new_mode(bus->controller)) {
             ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
--

2.41.0

#4 lore raw

PATCH 2/4 aspeed: Clean up local variable shadowing

In reply to Cédric Le Goater

Remove superfluous local 'irq' variables and use the one define at the top of the routine. This fixes warnings in aspeed_soc_ast2600_realize() such as :

../hw/arm/aspeed_ast2600.c: In function ‘aspeed_soc_ast2600_realize’:
../hw/arm/aspeed_ast2600.c:420:18: warning: declaration of ‘irq’ shadows a previous local [-Wshadow=compatible-local]

    420 |         qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
        |                  ^~~
  ../hw/arm/aspeed_ast2600.c:312:14: note: shadowed declaration is here
    312 |     qemu_irq irq;
        |              ^~~
---
 hw/arm/aspeed_ast2600.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/arm/aspeed_ast2600.c +5 -5
index a8b3a8065a11..e122e1c32d42 100644
@@ -388,7 +388,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->timerctrl), 0,
                     sc->memmap[ASPEED_DEV_TIMER1]);
     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
-        qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
+        irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
     }
 
@@ -413,8 +413,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     }
     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i2c), 0, sc->memmap[ASPEED_DEV_I2C]);
     for (i = 0; i < ASPEED_I2C_GET_CLASS(&s->i2c)->num_busses; i++) {
-        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
-                                        sc->irqmap[ASPEED_DEV_I2C] + i);
+        irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                               sc->irqmap[ASPEED_DEV_I2C] + i);
         /* The AST2600 I2C controller has one IRQ per bus. */
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq);
     }
@@ -611,8 +611,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     }
     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i3c), 0, sc->memmap[ASPEED_DEV_I3C]);
     for (i = 0; i < ASPEED_I3C_NR_DEVICES; i++) {
-        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
-                                        sc->irqmap[ASPEED_DEV_I3C] + i);
+        irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                               sc->irqmap[ASPEED_DEV_I3C] + i);
         /* The AST2600 I3C controller has one IRQ per bus. */
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i3c.devices[i]), 0, irq);
     }
Signature · 1 line
2.41.0
Reviewed-by on v1 2/4
#5 lore raw
Quoted 12 lines · Cédric Le Goater

Remove superfluous local 'irq' variables and use the one define at the top of the routine. This fixes warnings in aspeed_soc_ast2600_realize() such as :

   ../hw/arm/aspeed_ast2600.c: In function ‘aspeed_soc_ast2600_realize’:
   ../hw/arm/aspeed_ast2600.c:420:18: warning: declaration of ‘irq’ shadows a previous local [-Wshadow=compatible-local]
     420 |         qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
         |                  ^~~
   ../hw/arm/aspeed_ast2600.c:312:14: note: shadowed declaration is here
     312 |     qemu_irq irq;
         |              ^~~
Quoted 4 lines
---
  hw/arm/aspeed_ast2600.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
#6 lore raw
In reply to Cédric Le Goater
Quoted 42 lines · Cédric Le Goater

Remove superfluous local 'irq' variables and use the one define at the top of the routine. This fixes warnings in aspeed_soc_ast2600_realize() such as :

../hw/arm/aspeed_ast2600.c: In function ‘aspeed_soc_ast2600_realize’:
../hw/arm/aspeed_ast2600.c:420:18: warning: declaration of ‘irq’ shadows a previous local [-Wshadow=compatible-local]

    420 |         qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
        |                  ^~~
  ../hw/arm/aspeed_ast2600.c:312:14: note: shadowed declaration is here
    312 |     qemu_irq irq;
        |              ^~~
---
 hw/arm/aspeed_ast2600.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
hw/arm/aspeed_ast2600.c +3 -3
index a8b3a8065a11..e122e1c32d42 100644
@@ -388,7 +388,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->timerctrl), 0,
                     sc->memmap[ASPEED_DEV_TIMER1]);
     for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
-        qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
+        irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
     }
 
@@ -413,8 +413,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     }
     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i2c), 0, sc->memmap[ASPEED_DEV_I2C]);
     for (i = 0; i < ASPEED_I2C_GET_CLASS(&s->i2c)->num_busses; i++) {
-        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
-                                        sc->irqmap[ASPEED_DEV_I2C] + i);
+        irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                               sc->irqmap[ASPEED_DEV_I2C] + i);
         /* The AST2600 I2C controller has one IRQ per bus. */
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq);
     }

hw/arm/aspeed_ast2600.c static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) · line 618

Quoted 10 lines
hw/arm/aspeed_ast2600.c +2 -2
@@ -611,8 +611,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     }
     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i3c), 0, sc->memmap[ASPEED_DEV_I3C]);
     for (i = 0; i < ASPEED_I3C_NR_DEVICES; i++) {
-        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
-                                        sc->irqmap[ASPEED_DEV_I3C] + i);
+        irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                               sc->irqmap[ASPEED_DEV_I3C] + i);
         /* The AST2600 I3C controller has one IRQ per bus. */
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i3c.devices[i]), 0, irq);
     }

Clashes with Philippe's

[PATCH v2 10/22] hw/arm/aspeed: Clean up local variable shadowing
Message-ID: <[email protected]>

The difference is a matter of taste: one @irq in function scope vs. four in nested scopes. I'd prefer the former, i.e. this patch, but maintainers' preference matter more than mine. If you want me to merge together with other shadowing patches, tell me your preference, if any.

#7 lore raw
Quoted 57 lines · Markus Armbruster
Quoted 42 lines · Cédric Le Goater

Remove superfluous local 'irq' variables and use the one define at the top of the routine. This fixes warnings in aspeed_soc_ast2600_realize() such as :

   ../hw/arm/aspeed_ast2600.c: In function ‘aspeed_soc_ast2600_realize’:
   ../hw/arm/aspeed_ast2600.c:420:18: warning: declaration of ‘irq’ shadows a previous local [-Wshadow=compatible-local]
     420 |         qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
         |                  ^~~
   ../hw/arm/aspeed_ast2600.c:312:14: note: shadowed declaration is here
     312 |     qemu_irq irq;
         |              ^~~
---
  hw/arm/aspeed_ast2600.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)
hw/arm/aspeed_ast2600.c +3 -3
index a8b3a8065a11..e122e1c32d42 100644
@@ -388,7 +388,7 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
      aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->timerctrl), 0,
                      sc->memmap[ASPEED_DEV_TIMER1]);
      for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
-        qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
+        irq = aspeed_soc_get_irq(s, ASPEED_DEV_TIMER1 + i);
          sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
      }
 
@@ -413,8 +413,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
      }
      aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i2c), 0, sc->memmap[ASPEED_DEV_I2C]);
      for (i = 0; i < ASPEED_I2C_GET_CLASS(&s->i2c)->num_busses; i++) {
-        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
-                                        sc->irqmap[ASPEED_DEV_I2C] + i);
+        irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                               sc->irqmap[ASPEED_DEV_I2C] + i);
          /* The AST2600 I2C controller has one IRQ per bus. */
          sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq);
      }

hw/arm/aspeed_ast2600.c static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) · line 618

Quoted 10 lines
hw/arm/aspeed_ast2600.c +2 -2
@@ -611,8 +611,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
      }
      aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->i3c), 0, sc->memmap[ASPEED_DEV_I3C]);
      for (i = 0; i < ASPEED_I3C_NR_DEVICES; i++) {
-        qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
-                                        sc->irqmap[ASPEED_DEV_I3C] + i);
+        irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                               sc->irqmap[ASPEED_DEV_I3C] + i);
          /* The AST2600 I3C controller has one IRQ per bus. */
          sysbus_connect_irq(SYS_BUS_DEVICE(&s->i3c.devices[i]), 0, irq);
      }

Clashes with Philippe's

Quoted 7 lines

[PATCH v2 10/22] hw/arm/aspeed: Clean up local variable shadowing
Message-ID: <[email protected]>

The difference is a matter of taste: one @irq in function scope vs. four in nested scopes. I'd prefer the former, i.e. this patch, but maintainers' preference matter more than mine. If you want me to merge together with other shadowing patches, tell me your preference, if any.

You are the one gathering patches. Please choose. I don't mind.

Thanks,

C.

#8 lore raw

PATCH 3/4 aspeed/i3c: Rename variable shadowing a local

In reply to Cédric Le Goater

to fix warning :

../hw/i3c/aspeed_i3c.c: In function ‘aspeed_i3c_realize’:
../hw/i3c/aspeed_i3c.c:1959:17: warning: declaration of ‘dev’ shadows a parameter [-Wshadow=local]
1959 | Object *dev = OBJECT(&s->devices[i]);
| ^~~
../hw/i3c/aspeed_i3c.c:1942:45: note: shadowed declaration is here
1942 | static void aspeed_i3c_realize(DeviceState *dev, Error **errp)

        |                                ~~~~~~~~~~~~~^~~
---
 hw/misc/aspeed_i3c.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/aspeed_i3c.c +3 -3
index f54f5da522b3..d1ff61767167 100644
@@ -296,13 +296,13 @@ static void aspeed_i3c_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);
 
     for (i = 0; i < ASPEED_I3C_NR_DEVICES; ++i) {
-        Object *dev = OBJECT(&s->devices[i]);
+        Object *i3c_dev = OBJECT(&s->devices[i]);
 
-        if (!object_property_set_uint(dev, "device-id", i, errp)) {
+        if (!object_property_set_uint(i3c_dev, "device-id", i, errp)) {
             return;
         }
 
-        if (!sysbus_realize(SYS_BUS_DEVICE(dev), errp)) {
+        if (!sysbus_realize(SYS_BUS_DEVICE(i3c_dev), errp)) {
             return;
         }
 
Signature · 1 line
2.41.0
Reviewed-by on v1 3/4
#9 lore raw

Re: [PATCH 3/4] aspeed/i3c: Rename variable shadowing a local

hw/misc/aspeed_i3c.c static void aspeed_i3c_realize(DeviceState *dev, Error **errp)

Quoted 20 lines · Cédric Le Goater

to fix warning :

../hw/i3c/aspeed_i3c.c: In function ‘aspeed_i3c_realize’:
../hw/i3c/aspeed_i3c.c:1959:17: warning: declaration of ‘dev’ shadows a parameter [-Wshadow=local]

    1959 |         Object *dev = OBJECT(&s->devices[i]);
         |                 ^~~

../hw/i3c/aspeed_i3c.c:1942:45: note: shadowed declaration is here
1942 | static void aspeed_i3c_realize(DeviceState *dev, Error **errp)
| ~~~~~~~~~~~~~^~~

---
  hw/misc/aspeed_i3c.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/aspeed_i3c.c +0 -0
index f54f5da522b3..d1ff61767167 100644
@@ -296,13 +296,13 @@ static void aspeed_i3c_realize(DeviceState *dev, Error **errp)

Alternatively:

-- >8 --

-static void aspeed_i3c_realize(DeviceState *dev, Error **errp) +static void aspeed_i3c_realize(DeviceState *ctrl, Error **errp)

 {
     int i;
-    AspeedI3CState *s = ASPEED_I3C(dev);
-    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    AspeedI3CState *s = ASPEED_I3C(ctrl);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(ctrl);

---

Quoted 6 lines
hw/misc/aspeed_i3c.c +1 -1
      memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);
 
      for (i = 0; i < ASPEED_I3C_NR_DEVICES; ++i) {
-        Object *dev = OBJECT(&s->devices[i]);
+        Object *i3c_dev = OBJECT(&s->devices[i]);
 

hw/misc/aspeed_i3c.c static void aspeed_i3c_realize(DeviceState *dev, Error **errp) · line 308

Quoted 10 lines
hw/misc/aspeed_i3c.c +2 -2
-        if (!object_property_set_uint(dev, "device-id", i, errp)) {
+        if (!object_property_set_uint(i3c_dev, "device-id", i, errp)) {
              return;
          }
 
-        if (!sysbus_realize(SYS_BUS_DEVICE(dev), errp)) {
+        if (!sysbus_realize(SYS_BUS_DEVICE(i3c_dev), errp)) {
              return;
          }
 
Reviewed-by
#10 lore raw

Re: [PATCH 3/4] aspeed/i3c: Rename variable shadowing a local

Quoted 26 lines · Philippe Mathieu-Daudé

hw/misc/aspeed_i3c.c static void aspeed_i3c_realize(DeviceState *dev, Error **errp)

Quoted 20 lines · Cédric Le Goater

to fix warning :

../hw/i3c/aspeed_i3c.c: In function ‘aspeed_i3c_realize’:
../hw/i3c/aspeed_i3c.c:1959:17: warning: declaration of ‘dev’ shadows a parameter [-Wshadow=local]

    1959 |         Object *dev = OBJECT(&s->devices[i]);
         |                 ^~~

../hw/i3c/aspeed_i3c.c:1942:45: note: shadowed declaration is here
1942 | static void aspeed_i3c_realize(DeviceState *dev, Error **errp)
| ~~~~~~~~~~~~~^~~

---
  hw/misc/aspeed_i3c.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/aspeed_i3c.c +0 -0
index f54f5da522b3..d1ff61767167 100644
@@ -296,13 +296,13 @@ static void aspeed_i3c_realize(DeviceState *dev, Error **errp)

Alternatively:

-- >8 --

Review

Quoted 8 lines
(quoted diff) +3 -3
-static void aspeed_i3c_realize(DeviceState *dev, Error **errp)
+static void aspeed_i3c_realize(DeviceState *ctrl, Error **errp)
  {
      int i;
-    AspeedI3CState *s = ASPEED_I3C(dev);
-    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    AspeedI3CState *s = ASPEED_I3C(ctrl);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(ctrl);

Hmm, I feel like dev isn't an unreasonable or unusual name for the formal parameter? Switching to ctrl isn't my immediate preference.

Quoted 8 lines

---

Quoted 5 lines
hw/misc/aspeed_i3c.c +1 -1
      memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);
 
      for (i = 0; i < ASPEED_I3C_NR_DEVICES; ++i) {
-        Object *dev = OBJECT(&s->devices[i]);
+        Object *i3c_dev = OBJECT(&s->devices[i]);

Maybe s/i3c_dev/subdev? I dunno. That bikeshed isn't gonna get painted on its own.

Quoted 13 lines

hw/misc/aspeed_i3c.c static void aspeed_i3c_realize(DeviceState *dev, Error **errp) · line 308

Quoted 11 lines
hw/misc/aspeed_i3c.c +2 -2
-        if (!object_property_set_uint(dev, "device-id", i, errp)) {
+        if (!object_property_set_uint(i3c_dev, "device-id", i, errp)) {
              return;
          }
 
-        if (!sysbus_realize(SYS_BUS_DEVICE(dev), errp)) {
+        if (!sysbus_realize(SYS_BUS_DEVICE(i3c_dev), errp)) {
              return;
          }
 
#11 lore raw

PATCH 4/4 aspeed/timer: Clean up local variable shadowing

In reply to Cédric Le Goater

commit 8137355e850f ("aspeed/timer: Fix behaviour running Linux") introduced a MAX() expression to calculate the next timer deadline :

    return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));

The second MAX() is not necessary since the compared values are an unsigned and 0. Simply remove it and fix warning :

../hw/timer/aspeed_timer.c: In function ‘calculate_next’:
../include/qemu/osdep.h:396:31: warning: declaration of ‘_a’ shadows a previous local [-Wshadow=compatible-local]

    396 |         typeof(1 ? (a) : (b)) _a = (a), _b = (b);       \
        |                               ^~
  ../hw/timer/aspeed_timer.c:170:12: note: in expansion of macro ‘MAX’
    170 |     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
        |            ^~~
  ../hw/timer/aspeed_timer.c:170:16: note: in expansion of macro ‘MAX’
    170 |     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
        |                ^~~
  /home/legoater/work/qemu/qemu-aspeed.git/include/qemu/osdep.h:396:31: note: shadowed declaration is here
    396 |         typeof(1 ? (a) : (b)) _a = (a), _b = (b);       \
        |                               ^~
  ../hw/timer/aspeed_timer.c:170:12: note: in expansion of macro ‘MAX’
    170 |     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
        |            ^~~
Cc Joel Stanley <[email protected]>
Cc Andrew Jeffery <[email protected]>
---
 hw/timer/aspeed_timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/aspeed_timer.c +1 -1
index 9c20b3d6ad8a..72161f07bbee 100644
@@ -167,7 +167,7 @@ static uint64_t calculate_next(struct AspeedTimer *t)
         qemu_set_irq(t->irq, t->level);
     }
 
-    next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
+    next = MAX(calculate_match(t, 0), calculate_match(t, 1));
     t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
     return calculate_time(t, next);
Signature · 1 line
2.41.0
Reviewed-by on v1 4/4
#12 lore raw

Re: [PATCH 4/4] aspeed/timer: Clean up local variable shadowing

Quoted 25 lines · Cédric Le Goater

commit 8137355e850f ("aspeed/timer: Fix behaviour running Linux") introduced a MAX() expression to calculate the next timer deadline :

     return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));

The second MAX() is not necessary since the compared values are an unsigned and 0. Simply remove it and fix warning :

../hw/timer/aspeed_timer.c: In function ‘calculate_next’:
../include/qemu/osdep.h:396:31: warning: declaration of ‘_a’ shadows a previous local [-Wshadow=compatible-local]

     396 |         typeof(1 ? (a) : (b)) _a = (a), _b = (b);       \
         |                               ^~
   ../hw/timer/aspeed_timer.c:170:12: note: in expansion of macro ‘MAX’
     170 |     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
         |            ^~~
   ../hw/timer/aspeed_timer.c:170:16: note: in expansion of macro ‘MAX’
     170 |     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
         |                ^~~
   /home/legoater/work/qemu/qemu-aspeed.git/include/qemu/osdep.h:396:31: note: shadowed declaration is here
     396 |         typeof(1 ? (a) : (b)) _a = (a), _b = (b);       \
         |                               ^~
   ../hw/timer/aspeed_timer.c:170:12: note: in expansion of macro ‘MAX’
     170 |     next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
         |            ^~~
Quoted 6 lines
Cc Joel Stanley <[email protected]>
Cc Andrew Jeffery <[email protected]>
---
  hw/timer/aspeed_timer.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
#13 lore raw
In reply to Cédric Le Goater
Quoted 7 lines · Cédric Le Goater

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Could you please double check patch 4 ?

Could Markus' MAKE_IDENTFIER() help there?

Quoted 17 lines

Thanks,

C.

Cédric Le Goater (4):
aspeed/i2c: Clean up local variable shadowing
aspeed: Clean up local variable shadowing aspeed/i3c: Rename variable shadowing a local aspeed/timer: Clean up local variable shadowing

  hw/arm/aspeed_ast2600.c | 10 +++++-----
  hw/i2c/aspeed_i2c.c     |  1 -
  hw/misc/aspeed_i3c.c    |  6 +++---
  hw/timer/aspeed_timer.c |  2 +-
  4 files changed, 9 insertions(+), 10 deletions(-)
#14 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Cédric Le Goater

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Could you please double check patch 4 ?

Could Markus' MAKE_IDENTFIER() help there?

ah ! you typed too fast and I also read too fast, as :

MARKUS_IDENTIFIER()

and I liked it :) but what is MAKE_IDENTIFIER ? really, please explain.

Thanks,

C.

#15 lore raw
Quoted 8 lines · Cédric Le Goater
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Cédric Le Goater

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Could you please double check patch 4 ?

Could Markus' MAKE_IDENTFIER() help there?

ah ! you typed too fast and I also read too fast, as :

MARKUS_IDENTIFIER()

and I liked it :)

LOL

Quoted 1 line

but what is MAKE_IDENTIFIER ? really, please explain.

Philippe is referring to

[PATCH v3 7/7] qobject atomics osdep: Make a few macros more hygienic
Message-ID: <[email protected]>

which tweaks MAX() to permit nesting without shadowing. Your PATCH 4 may not be needed if you base on it.

MAKE_IDENTIFIER() is a helper macro introduced in that patch.

You can fetch the patch from https://repo.or.cz/qemu/armbru.git branch shadow-next, along with collected other shadowing patches.

Questions?

#16 lore raw
Quoted 23 lines · Markus Armbruster
Quoted 8 lines · Cédric Le Goater
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Cédric Le Goater

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Could you please double check patch 4 ?

Could Markus' MAKE_IDENTFIER() help there?

ah ! you typed too fast and I also read too fast, as :

MARKUS_IDENTIFIER()

and I liked it :)

LOL

Quoted 1 line

but what is MAKE_IDENTIFIER ? really, please explain.

Quoted 7 lines

Philippe is referring to

[PATCH v3 7/7] qobject atomics osdep: Make a few macros more hygienic
Message-ID: <[email protected]>

which tweaks MAX() to permit nesting without shadowing. Your PATCH 4 may not be needed if you base on it.

We don't need the nested MAX(). PATCH 4 is a cleanup which happens to remove the shadowing. Let's keep it the way it is.

Quoted 4 lines

MAKE_IDENTIFIER() is a helper macro introduced in that patch.

You can fetch the patch from https://repo.or.cz/qemu/armbru.git branch shadow-next, along with collected other shadowing patches.

OK.

Would you prefer maintainers to include the shadowing changes in a potential PR they would send or would you rather take care of it in a PR of your own ?

Thanks,

C.

#17 lore raw
Quoted 39 lines · Cédric Le Goater
Quoted 23 lines · Markus Armbruster
Quoted 8 lines · Cédric Le Goater
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Cédric Le Goater

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

Could you please double check patch 4 ?

Could Markus' MAKE_IDENTFIER() help there?

ah ! you typed too fast and I also read too fast, as :

MARKUS_IDENTIFIER()

and I liked it :)

LOL

Quoted 1 line

but what is MAKE_IDENTIFIER ? really, please explain.

Quoted 7 lines

Philippe is referring to

[PATCH v3 7/7] qobject atomics osdep: Make a few macros more hygienic
Message-ID: <[email protected]>

which tweaks MAX() to permit nesting without shadowing. Your PATCH 4 may not be needed if you base on it.

We don't need the nested MAX(). PATCH 4 is a cleanup which happens to remove the shadowing. Let's keep it the way it is.

Quoted 3 lines

MAKE_IDENTIFIER() is a helper macro introduced in that patch. You can fetch the patch from https://repo.or.cz/qemu/armbru.git branch shadow-next, along with collected other shadowing patches.

Quoted 5 lines

OK.

Would you prefer maintainers to include the shadowing changes in a potential PR they would send or would you rather take care of it in a PR of your own ?

I'm happy to collect patches and do pull requests. I don't mind maintainers merging patches for their subsystems; interference should be minimal.

Thanks!

#18 lore raw
In reply to Cédric Le Goater
Quoted 11 lines · Cédric Le Goater

Hello,

Here are cleanups for local variable shadowing warnings in aspeed models.

Joel, Andrew,

Could you please double check patch 4 ?

Thanks,

C.

Queued, thanks!