[PATCH] clk: qcom: clk-rpmh: prevent integer overflow in recalc_rate

Anastasia Belova posted 1 patch 1 year, 2 months ago
drivers/clk/qcom/clk-rpmh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] clk: qcom: clk-rpmh: prevent integer overflow in recalc_rate
Posted by Anastasia Belova 1 year, 2 months ago
aggr_state and unit fields are u32. The result of their
multiplication may not fit in this type.

Add explicit casting to prevent overflow.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 04053f4d23a4 ("clk: qcom: clk-rpmh: Add IPA clock support")
Cc: stable@vger.kernel.org # 5.4+
Signed-off-by: Anastasia Belova <abelova@astralinux.ru>
---
 drivers/clk/qcom/clk-rpmh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/qcom/clk-rpmh.c b/drivers/clk/qcom/clk-rpmh.c
index eefc322ce367..e6c33010cfbf 100644
--- a/drivers/clk/qcom/clk-rpmh.c
+++ b/drivers/clk/qcom/clk-rpmh.c
@@ -329,7 +329,7 @@ static unsigned long clk_rpmh_bcm_recalc_rate(struct clk_hw *hw,
 {
 	struct clk_rpmh *c = to_clk_rpmh(hw);
 
-	return c->aggr_state * c->unit;
+	return (unsigned long)c->aggr_state * c->unit;
 }
 
 static const struct clk_ops clk_rpmh_bcm_ops = {
-- 
2.30.2
Re: [PATCH] clk: qcom: clk-rpmh: prevent integer overflow in recalc_rate
Posted by Bjorn Andersson 1 year, 1 month ago
On Tue, 03 Dec 2024 11:42:31 +0300, Anastasia Belova wrote:
> aggr_state and unit fields are u32. The result of their
> multiplication may not fit in this type.
> 
> Add explicit casting to prevent overflow.
> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> [...]

Applied, thanks!

[1/1] clk: qcom: clk-rpmh: prevent integer overflow in recalc_rate
      commit: 89aa5925d201b90a48416784831916ca203658f9

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>