diff mbox series

[RESEND] clk: sunxi: Fix incorrect usage of round_down()

Message ID 20200317211333.2597793-1-rikard.falkeborn@gmail.com (mailing list archive)
State Mainlined
Commit ee25d9742dabed3fd18158b518f846abeb70f319
Headers show
Series [RESEND] clk: sunxi: Fix incorrect usage of round_down() | expand

Commit Message

Rikard Falkeborn March 17, 2020, 9:13 p.m. UTC
round_down() can only round to powers of 2. If round_down() is asked
to round to something that is not a power of 2, incorrect results are
produced. The incorrect results can be both too large and too small.

Instead, use rounddown() which can round to any number.

Fixes: 6a721db180a2 ("clk: sunxi: Add A31 clocks support")
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
---
Resend to include lists, appologies for missing that.

Patch has only been compile tested, I don't have the hardware.

 drivers/clk/sunxi/clk-sunxi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

maxime@cerno.tech March 24, 2020, 3:37 p.m. UTC | #1
On Tue, Mar 17, 2020 at 10:13:32PM +0100, Rikard Falkeborn wrote:
> round_down() can only round to powers of 2. If round_down() is asked
> to round to something that is not a power of 2, incorrect results are
> produced. The incorrect results can be both too large and too small.
>
> Instead, use rounddown() which can round to any number.
>
> Fixes: 6a721db180a2 ("clk: sunxi: Add A31 clocks support")
> Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>

Queued for 5.8, thanks!
Maxime
diff mbox series

Patch

diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index 27201fd26e44..e1aa1fbac48a 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -90,7 +90,7 @@  static void sun6i_a31_get_pll1_factors(struct factors_request *req)
 	 * Round down the frequency to the closest multiple of either
 	 * 6 or 16
 	 */
-	u32 round_freq_6 = round_down(freq_mhz, 6);
+	u32 round_freq_6 = rounddown(freq_mhz, 6);
 	u32 round_freq_16 = round_down(freq_mhz, 16);
 
 	if (round_freq_6 > round_freq_16)