All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/intc/hex-l2vic: avoid shift into sign bit
@ 2026-10-23  8:46 Peter Maydell
  2026-10-23 10:22 ` Tommaso Califano
  2026-10-23 13:32 ` Brian Cain
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Maydell @ 2026-10-23  8:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: Brian Cain, Pierrick Bouvier

In fastl2vic_write() we do:
   val = 1 << (irq % 32);

Because '1' is a signed integer, this can shift into the sign
bit of 'int'; the cast to uint64_t to assign to 'val' then
results in all the high bits being set. This happens to cause
no visible problems because l2vic_write never looks at those
bits, but it's obviously not intended. Use 1ULL so that we
do the shift as 64 bits unsigned.

Resolves: Coverity CID 1685261
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/intc/hex-l2vic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/intc/hex-l2vic.c b/hw/intc/hex-l2vic.c
index 736f1be3b1d..89b44200928 100644
--- a/hw/intc/hex-l2vic.c
+++ b/hw/intc/hex-l2vic.c
@@ -381,7 +381,7 @@ static void fastl2vic_write(void *opaque, hwaddr offset, uint64_t val,
         uint32_t cmd = (val >> 16) & 0x3;
         uint32_t irq = val & 0x3ff;
         uint32_t slice = (irq / 32) * 4;
-        val = 1 << (irq % 32);
+        val = 1ULL << (irq % 32);
 
         if (cmd == FASTL2VIC_ENABLE) {
             l2vic_write(opaque, L2VIC_INT_ENABLE_SETn + slice, val, size);
-- 
2.43.0



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

* Re: [PATCH] hw/intc/hex-l2vic: avoid shift into sign bit
  2026-10-23  8:46 [PATCH] hw/intc/hex-l2vic: avoid shift into sign bit Peter Maydell
@ 2026-10-23 10:22 ` Tommaso Califano
  2026-10-23 13:32 ` Brian Cain
  1 sibling, 0 replies; 3+ messages in thread
From: Tommaso Califano @ 2026-10-23 10:22 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel
  Cc: Brian Cain, Pierrick Bouvier,
	qemu-devel-bounces+tcalifano=redhat.com

On Fri Oct 23, 2026 at 10:46 AM CEST, Peter Maydell wrote:
> In fastl2vic_write() we do:
>    val = 1 << (irq % 32);
>
> Because '1' is a signed integer, this can shift into the sign
> bit of 'int'; the cast to uint64_t to assign to 'val' then
> results in all the high bits being set. This happens to cause
> no visible problems because l2vic_write never looks at those
> bits, but it's obviously not intended. Use 1ULL so that we
> do the shift as 64 bits unsigned.
>
> Resolves: Coverity CID 1685261
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  hw/intc/hex-l2vic.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/intc/hex-l2vic.c b/hw/intc/hex-l2vic.c
> index 736f1be3b1d..89b44200928 100644
> --- a/hw/intc/hex-l2vic.c
> +++ b/hw/intc/hex-l2vic.c
> @@ -381,7 +381,7 @@ static void fastl2vic_write(void *opaque, hwaddr offset, uint64_t val,
>          uint32_t cmd = (val >> 16) & 0x3;
>          uint32_t irq = val & 0x3ff;
>          uint32_t slice = (irq / 32) * 4;
> -        val = 1 << (irq % 32);
> +        val = 1ULL << (irq % 32);
>  
>          if (cmd == FASTL2VIC_ENABLE) {
>              l2vic_write(opaque, L2VIC_INT_ENABLE_SETn + slice, val, size);


Not an expert, but LGTM.

Reviewed-by: Tommaso Califano <tcalifano@redhat.com>

Regards,
Tommaso



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

* Re: [PATCH] hw/intc/hex-l2vic: avoid shift into sign bit
  2026-10-23  8:46 [PATCH] hw/intc/hex-l2vic: avoid shift into sign bit Peter Maydell
  2026-10-23 10:22 ` Tommaso Califano
@ 2026-10-23 13:32 ` Brian Cain
  1 sibling, 0 replies; 3+ messages in thread
From: Brian Cain @ 2026-10-23 13:32 UTC (permalink / raw)
  To: Peter Maydell, qemu-devel; +Cc: Pierrick Bouvier


On 10/23/2026 3:46 AM, Peter Maydell wrote:
> In fastl2vic_write() we do:
>     val = 1 << (irq % 32);
>
> Because '1' is a signed integer, this can shift into the sign
> bit of 'int'; the cast to uint64_t to assign to 'val' then
> results in all the high bits being set. This happens to cause
> no visible problems because l2vic_write never looks at those
> bits, but it's obviously not intended. Use 1ULL so that we
> do the shift as 64 bits unsigned.
>
> Resolves: Coverity CID 1685261
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>   hw/intc/hex-l2vic.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com>


> diff --git a/hw/intc/hex-l2vic.c b/hw/intc/hex-l2vic.c
> index 736f1be3b1d..89b44200928 100644
> --- a/hw/intc/hex-l2vic.c
> +++ b/hw/intc/hex-l2vic.c
> @@ -381,7 +381,7 @@ static void fastl2vic_write(void *opaque, hwaddr offset, uint64_t val,
>           uint32_t cmd = (val >> 16) & 0x3;
>           uint32_t irq = val & 0x3ff;
>           uint32_t slice = (irq / 32) * 4;
> -        val = 1 << (irq % 32);
> +        val = 1ULL << (irq % 32);
>   
>           if (cmd == FASTL2VIC_ENABLE) {
>               l2vic_write(opaque, L2VIC_INT_ENABLE_SETn + slice, val, size);


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

end of thread, other threads:[~2026-10-23 13:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23  8:46 [PATCH] hw/intc/hex-l2vic: avoid shift into sign bit Peter Maydell
2026-10-23 10:22 ` Tommaso Califano
2026-10-23 13:32 ` Brian Cain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.