aspeed/smc: Fix possible integer overflow
PATCH 1/1 aspeed/smc: Fix possible integer overflow
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.
--- hw/ssi/aspeed_smc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +1 -2
@@ -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 (); }/*
Signature · 1 line
2.45.2
Quoted 22 lines · 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 calleraspeed_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 useg_assert_not_reached()instead.Fixes Coverity CID 1547822Suggested-by Peter Maydell <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/ssi/aspeed_smc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/ssi/aspeed_smc.c +0
-0
hw/ssi/aspeed_smc.c static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask) · line 847
Quoted 8 lines
hw/ssi/aspeed_smc.c +1
-2@@ -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 (); }
thanks
-- PMM
Cédric Le Goater
AppliedQuoted 21 lines · 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 calleraspeed_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 useg_assert_not_reached()instead.Fixes Coverity CID 1547822Suggested-by Peter Maydell <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/ssi/aspeed_smc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/ssi/aspeed_smc.c +0
-0
hw/ssi/aspeed_smc.c static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask) · line 848
Quoted 9 lines
hw/ssi/aspeed_smc.c +1
-2@@ -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.