]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
hw/gpio/aspeed_gpio: Avoid shift into sign bit
authorPeter Maydell <peter.maydell@linaro.org>
Fri, 30 Aug 2024 18:05:16 +0000 (19:05 +0100)
committerCédric Le Goater <clg@redhat.com>
Mon, 16 Sep 2024 15:44:07 +0000 (17:44 +0200)
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
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
hw/gpio/aspeed_gpio.c

index 3e7b35cf4f54091532b05d249f6340b454d22e14..71756664dd695f8020a8a21a8b74c37ce96f88ac 100644 (file)
@@ -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)) {