Skip to contentSkip to conversation

aspeed/smc: Fix possible integer overflow

PATCH Applied Cédric Le Goater 3 participants 3 messages Jul 12, 2024 – Jul 18, 2024 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

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.

Fixes Coverity CID 1547822
---
 hw/ssi/aspeed_smc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +1 -2
index b79815c2b8aa..7fd63669c10e 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 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
---
 hw/ssi/aspeed_smc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +0 -0
index b79815c2b8aa..7fd63669c10e 100644

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

#2 lore raw
In reply to Cédric Le Goater
Quoted 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 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
---
  hw/ssi/aspeed_smc.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
hw/ssi/aspeed_smc.c +0 -0
index b79815c2b8aa..7fd63669c10e 100644

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.