public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: si5341: Prevent division by zero in si5341_output_clk_determine_rate()
@ 2024-09-17  7:52 Aleksandr Mishin
  2024-09-19 10:35 ` Stephen Boyd
  2024-09-19 12:29 ` [PATCH v2] clk: si5341: Adjust rate rounding " Aleksandr Mishin
  0 siblings, 2 replies; 3+ messages in thread
From: Aleksandr Mishin @ 2024-09-17  7:52 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Aleksandr Mishin, Michael Turquette, Stephen Boyd, linux-clk,
	linux-kernel, lvc-project

In si5341_output_clk_determine_rate() division by zero is possible if the
following conditions are met:
- rate > (parent_rate / 2);
- (parent_rate / 2) is not multiple of rate;
- CLK_SET_RATE_PARENT flag is not set.

Add zero value check to prevent division by zero.

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

Fixes: 61c34af50c5f ("clk: si5341: Switch to determine_rate")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/clk/clk-si5341.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
index 6e8dd7387cfd..d0d68a5bba74 100644
--- a/drivers/clk/clk-si5341.c
+++ b/drivers/clk/clk-si5341.c
@@ -855,7 +855,7 @@ static int si5341_output_clk_determine_rate(struct clk_hw *hw,
 	} else {
 		/* We cannot change our parent's rate, report what we can do */
 		r /= rate;
-		rate = req->best_parent_rate / (r << 1);
+		rate = (r << 1) ? req->best_parent_rate / (r << 1) : 0;
 	}
 
 	req->rate = rate;
-- 
2.30.2


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

end of thread, other threads:[~2024-09-19 12:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-17  7:52 [PATCH] clk: si5341: Prevent division by zero in si5341_output_clk_determine_rate() Aleksandr Mishin
2024-09-19 10:35 ` Stephen Boyd
2024-09-19 12:29 ` [PATCH v2] clk: si5341: Adjust rate rounding " Aleksandr Mishin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox