c78883c8d6135bb3e34b6e01f75b639451239012
[openwrt/staging/ldir.git] / target / linux / at91 / patches-5.10 / 240-clk-at91-clk-master-check-if-div-or-pres-is-zero.patch
1 From bb8e6ca274763fa98613dbe8b0833348a1d8fe4d Mon Sep 17 00:00:00 2001
2 From: Claudiu Beznea <claudiu.beznea@microchip.com>
3 Date: Mon, 11 Oct 2021 14:27:12 +0300
4 Subject: [PATCH 240/247] clk: at91: clk-master: check if div or pres is zero
5
6 Check if div or pres is zero before using it as argument for ffs().
7 In case div is zero ffs() will return 0 and thus substracting from
8 zero will lead to invalid values to be setup in registers.
9
10 Fixes: 7a110b9107ed8 ("clk: at91: clk-master: re-factor master clock")
11 Fixes: 75c88143f3b87 ("clk: at91: clk-master: add master clock support for SAMA7G5")
12 Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
13 Link: https://lore.kernel.org/r/20211011112719.3951784-9-claudiu.beznea@microchip.com
14 Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
15 Signed-off-by: Stephen Boyd <sboyd@kernel.org>
16 ---
17 drivers/clk/at91/clk-master.c | 4 ++--
18 1 file changed, 2 insertions(+), 2 deletions(-)
19
20 --- a/drivers/clk/at91/clk-master.c
21 +++ b/drivers/clk/at91/clk-master.c
22 @@ -344,7 +344,7 @@ static int clk_master_pres_set_rate(stru
23
24 else if (pres == 3)
25 pres = MASTER_PRES_MAX;
26 - else
27 + else if (pres)
28 pres = ffs(pres) - 1;
29
30 spin_lock_irqsave(master->lock, flags);
31 @@ -757,7 +757,7 @@ static int clk_sama7g5_master_set_rate(s
32
33 if (div == 3)
34 div = MASTER_PRES_MAX;
35 - else
36 + else if (div)
37 div = ffs(div) - 1;
38
39 spin_lock_irqsave(master->lock, flags);