* [PATCH] aspeed/smc: Fix possible integer overflow
@ 2024-07-12 16:36 Cédric Le Goater
2024-07-12 16:39 ` Peter Maydell
2024-07-18 16:19 ` Cédric Le Goater
0 siblings, 2 replies; 3+ messages in thread
From: Cédric Le Goater @ 2024-07-12 16:36 UTC (permalink / raw)
To: qemu-arm, qemu-devel
Cc: Andrew Jeffery, Joel Stanley, Troy Lee, Jamin Lin, Peter Maydell,
Alistair Francis, Cédric Le Goater
Coverity reports a possible integer overflow because routine
aspeeed_smc_hclk_divisor() has a codepath returning 0, which could
lead to an integer overflow when computing variable 'hclk_shift' in
the caller aspeed_smc_dma_calibration().
The value passed to aspeed_smc_hclk_divisor() is always between 0 and
15 and, in this case, there is always a matching hclk divisor. Remove
the return 0 and use g_assert_not_reached() instead.
Fixes: Coverity CID 1547822
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/ssi/aspeed_smc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
index b79815c2b8aa..7fd63669c10e 100644
--- a/hw/ssi/aspeed_smc.c
+++ b/hw/ssi/aspeed_smc.c
@@ -842,8 +842,7 @@ static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask)
}
}
- aspeed_smc_error("invalid HCLK mask %x", hclk_mask);
- return 0;
+ g_assert_not_reached();
}
/*
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] aspeed/smc: Fix possible integer overflow
2024-07-12 16:36 [PATCH] aspeed/smc: Fix possible integer overflow Cédric Le Goater
@ 2024-07-12 16:39 ` Peter Maydell
2024-07-18 16:19 ` Cédric Le Goater
1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2024-07-12 16:39 UTC (permalink / raw)
To: Cédric Le Goater
Cc: qemu-arm, qemu-devel, Andrew Jeffery, Joel Stanley, Troy Lee,
Jamin Lin, Alistair Francis
On Fri, 12 Jul 2024 at 17:36, Cédric Le Goater <clg@redhat.com> wrote:
>
> Coverity reports a possible integer overflow because routine
> aspeeed_smc_hclk_divisor() has a codepath returning 0, which could
> lead to an integer overflow when computing variable 'hclk_shift' in
> the caller aspeed_smc_dma_calibration().
>
> The value passed to aspeed_smc_hclk_divisor() is always between 0 and
> 15 and, in this case, there is always a matching hclk divisor. Remove
> the return 0 and use g_assert_not_reached() instead.
>
> Fixes: Coverity CID 1547822
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> hw/ssi/aspeed_smc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
> index b79815c2b8aa..7fd63669c10e 100644
> --- a/hw/ssi/aspeed_smc.c
> +++ b/hw/ssi/aspeed_smc.c
> @@ -842,8 +842,7 @@ static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask)
> }
> }
>
> - aspeed_smc_error("invalid HCLK mask %x", hclk_mask);
> - return 0;
> + g_assert_not_reached();
> }
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] aspeed/smc: Fix possible integer overflow
2024-07-12 16:36 [PATCH] aspeed/smc: Fix possible integer overflow Cédric Le Goater
2024-07-12 16:39 ` Peter Maydell
@ 2024-07-18 16:19 ` Cédric Le Goater
1 sibling, 0 replies; 3+ messages in thread
From: Cédric Le Goater @ 2024-07-18 16:19 UTC (permalink / raw)
To: Cédric Le Goater, qemu-arm, qemu-devel
Cc: Andrew Jeffery, Joel Stanley, Troy Lee, Jamin Lin, Peter Maydell,
Alistair Francis
On 7/12/24 18:36, Cédric Le Goater wrote:
> Coverity reports a possible integer overflow because routine
> aspeeed_smc_hclk_divisor() has a codepath returning 0, which could
> lead to an integer overflow when computing variable 'hclk_shift' in
> the caller aspeed_smc_dma_calibration().
>
> The value passed to aspeed_smc_hclk_divisor() is always between 0 and
> 15 and, in this case, there is always a matching hclk divisor. Remove
> the return 0 and use g_assert_not_reached() instead.
>
> Fixes: Coverity CID 1547822
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Cédric Le Goater <clg@redhat.com>
> ---
> hw/ssi/aspeed_smc.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
> index b79815c2b8aa..7fd63669c10e 100644
> --- a/hw/ssi/aspeed_smc.c
> +++ b/hw/ssi/aspeed_smc.c
> @@ -842,8 +842,7 @@ static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask)
> }
> }
>
> - aspeed_smc_error("invalid HCLK mask %x", hclk_mask);
> - return 0;
> + g_assert_not_reached();
> }
>
> /*
Applied to aspeed-next.
Thanks,
C.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-18 16:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 16:36 [PATCH] aspeed/smc: Fix possible integer overflow Cédric Le Goater
2024-07-12 16:39 ` Peter Maydell
2024-07-18 16:19 ` 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).