[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20241016101122.2092-1-adiupina@astralinux.ru>
Date: Wed, 16 Oct 2024 13:11:22 +0300
From: Alexandra Diupina <adiupina@...ralinux.ru>
To: Andrew Lunn <andrew@...n.ch>
Cc: Alexandra Diupina <adiupina@...ralinux.ru>,
Gregory Clement <gregory.clement@...tlin.com>,
Sebastian Hesselbarth <sebastian.hesselbarth@...il.com>,
Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
linux-clk@...r.kernel.org,
linux-kernel@...r.kernel.org,
lvc-project@...uxtesting.org,
Fedor Pchelkin <pchelkin@...ras.ru>
Subject: [PATCH v5] clk: mvebu: Prevent division by zero in clk_double_div_recalc_rate()
It is not known exactly what values can be contained in the registers
at the addresses DIV_SEL0, DIV_SEL1, DIV_SEL2, so the return value of
get_div() can be zero.
The documentation does not describe the behavior of hardware when
receiving a zero rate divider, so add warning assertion and bail out
with a default value if it is violated to prevent division by zero.
Non panic_on_warn systems would at least survive in this case but
still have a valuable trace. The warning assertion would state in
the code that the condition is very unexpected and most probably
won't ever happen but not 100% sure because it depends on hardware
behavior.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Suggested-by: Fedor Pchelkin <pchelkin@...ras.ru>
Signed-off-by: Alexandra Diupina <adiupina@...ralinux.ru>
---
v5: using WARN_ON_ONCE() and changing the commit message
v4: replace hw->init->name with clk_hw_get_name(hw)
v3: fix indentation
v2: added explanations to the commit message and printing
of an error message when div==0
drivers/clk/mvebu/armada-37xx-periph.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c
index 13906e31bef8..ad7b477596ed 100644
--- a/drivers/clk/mvebu/armada-37xx-periph.c
+++ b/drivers/clk/mvebu/armada-37xx-periph.c
@@ -343,6 +343,9 @@ 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);
+ if (WARN_ON_ONCE(!div))
+ return 0;
+
return DIV_ROUND_UP_ULL((u64)parent_rate, div);
}
--
2.30.2
Powered by blists - more mailing lists