linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: mvebu: Prevent division by zero in clk_double_div_recalc_rate()
@ 2024-09-09 13:38 Alexandra Diupina
  2024-09-09 14:02 ` Andrew Lunn
  0 siblings, 1 reply; 14+ messages in thread
From: Alexandra Diupina @ 2024-09-09 13:38 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Alexandra Diupina, Gregory Clement, Sebastian Hesselbarth,
	Michael Turquette, Stephen Boyd, linux-arm-kernel, linux-clk,
	linux-kernel, lvc-project

get_div() may return zero, so it is necessary to check
before calling DIV_ROUND_UP_ULL().

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

Fixes: 8ca4746a78ab ("clk: mvebu: Add the peripheral clock driver for Armada 3700")
Signed-off-by: Alexandra Diupina <adiupina@astralinux.ru>
---
 drivers/clk/mvebu/armada-37xx-periph.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
index 8701a58a5804..d0e1d591e4f2 100644
--- a/drivers/clk/mvebu/armada-37xx-periph.c
+++ b/drivers/clk/mvebu/armada-37xx-periph.c
@@ -343,7 +343,10 @@ static unsigned long clk_double_div_recalc_rate(struct clk_hw *hw,
 	div = get_div(double_div->reg1, double_div->shift1);
 	div *= get_div(double_div->reg2, double_div->shift2);
 
-	return DIV_ROUND_UP_ULL((u64)parent_rate, div);
+	if (!div)
+		return 0;
+	else
+		return DIV_ROUND_UP_ULL((u64)parent_rate, div);
 }
 
 static const struct clk_ops clk_double_div_ops = {
-- 
2.30.2



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

end of thread, other threads:[~2024-10-09 13:46 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 13:38 [PATCH] clk: mvebu: Prevent division by zero in clk_double_div_recalc_rate() Alexandra Diupina
2024-09-09 14:02 ` Andrew Lunn
2024-09-09 14:17   ` Alexandra Diupina
2024-09-09 14:34     ` Andrew Lunn
2024-09-10 17:31       ` [PATCH v2] " Alexandra Diupina
2024-09-10 18:59         ` Andrew Lunn
2024-09-17 13:22           ` [PATCH v3] " Alexandra Diupina
2024-09-19 10:24             ` Stephen Boyd
2024-09-24 13:14               ` Alexandra Diupina
2024-10-07 22:56                 ` Stephen Boyd
2024-10-08 21:58                   ` Andrew Lunn
2024-10-09  9:01                     ` [lvc-project] " Fedor Pchelkin
2024-10-09 12:23                       ` Andrew Lunn
2024-10-09 13:43                         ` Fedor Pchelkin

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).