Skip to contentSkip to conversation

hw/gpio/aspeed_gpio: Avoid shift into sign bit

PATCH Applied Peter Maydell 2 participants 2 messages Aug 30, 2024 – Sep 2, 2024 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/gpio/aspeed_gpio: Avoid shift into sign bit

In aspeed_gpio_update() we calculate "mask = 1 << gpio", where gpio can be between 0 and 31. Coverity complains about this because 1 << 31 won't fit in a signed integer.

For QEMU this isn't an error because we enable -fwrapv, but we can keep Coverity happy by doing the shift on unsigned numbers.

Resolves: Coverity CID 1547742

---
Very minor but I'm just fixing a few easy issues on a Friday evening :-)

 hw/gpio/aspeed_gpio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/gpio/aspeed_gpio.c +1 -1
index 6474bb8de5b..d6ccf63a2ff 100644
@@ -281,7 +281,7 @@ static void aspeed_gpio_update(AspeedGPIOState *s, GPIOSets *regs,
     diff &= mode_mask;
     if (diff) {
         for (gpio = 0; gpio < ASPEED_GPIOS_PER_SET; gpio++) {
-            uint32_t mask = 1 << gpio;
+            uint32_t mask = 1U << gpio;
 
             /* If the gpio needs to be updated... */
             if (!(diff & mask)) {
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 10 lines · Peter Maydell

In aspeed_gpio_update() we calculate "mask = 1 << gpio", where gpio can be between 0 and 31. Coverity complains about this because 1 << 31 won't fit in a signed integer.

For QEMU this isn't an error because we enable -fwrapv, but we can keep Coverity happy by doing the shift on unsigned numbers.

Resolves: Coverity CID 1547742

Applied to aspeed-next.

Thanks,

C.