qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/gpio/aspeed_gpio: Avoid shift into sign bit
@ 2024-08-30 18:05 Peter Maydell
  2024-09-02  5:58 ` Cédric Le Goater
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2024-08-30 18:05 UTC (permalink / raw)
  To: qemu-arm, qemu-devel; +Cc: Cédric Le Goater

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>
---
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(-)

diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c
index 6474bb8de5b..d6ccf63a2ff 100644
--- a/hw/gpio/aspeed_gpio.c
+++ b/hw/gpio/aspeed_gpio.c
@@ -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)) {
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hw/gpio/aspeed_gpio: Avoid shift into sign bit
  2024-08-30 18:05 [PATCH] hw/gpio/aspeed_gpio: Avoid shift into sign bit Peter Maydell
@ 2024-09-02  5:58 ` Cédric Le Goater
  0 siblings, 0 replies; 2+ messages in thread
From: Cédric Le Goater @ 2024-09-02  5:58 UTC (permalink / raw)
  To: Peter Maydell, qemu-arm, qemu-devel

On 8/30/24 20:05, Peter Maydell wrote:
> 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>


Applied to aspeed-next.

Thanks,

C.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-09-02  6:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-30 18:05 [PATCH] hw/gpio/aspeed_gpio: Avoid shift into sign bit Peter Maydell
2024-09-02  5:58 ` Cédric Le Goater

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).