* [PATCH v2] clk: hisilicon: Remove unnecessary local variable
@ 2024-08-01 10:36 Thorsten Blum
2024-08-01 17:18 ` Uwe Kleine-König
2024-08-08 19:53 ` Stephen Boyd
0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2024-08-01 10:36 UTC (permalink / raw)
To: mturquette, sboyd, erick.archer, gustavoars, u.kleine-koenig,
christophe.jaillet
Cc: linux-clk, linux-kernel, Thorsten Blum
The local u64 variable refdiv_val has the same value as the local u32
variable val and can be removed. Remove it and use val directly as the
divisor to also remove the following Coccinelle/coccicheck warning
reported by do_div.cocci:
WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead
Use the preferred div_u64() function instead of the do_div() macro.
Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
Changes in v2:
- Use div_u64() instead of do_div() as suggested by Stephen Boyd
- Link to v1: https://lore.kernel.org/linux-kernel/20240710201844.710365-2-thorsten.blum@toblux.com/
---
drivers/clk/hisilicon/clk-hi3559a.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/clk-hi3559a.c
index c79a94f6d9d2..8646e9d352ed 100644
--- a/drivers/clk/hisilicon/clk-hi3559a.c
+++ b/drivers/clk/hisilicon/clk-hi3559a.c
@@ -407,7 +407,7 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct hi3559av100_clk_pll *clk = to_pll_clk(hw);
- u64 frac_val, fbdiv_val, refdiv_val;
+ u64 frac_val, fbdiv_val;
u32 postdiv1_val, postdiv2_val;
u32 val;
u64 tmp, rate;
@@ -435,14 +435,13 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
val = readl_relaxed(clk->ctrl_reg2);
val = val >> clk->refdiv_shift;
val &= ((1 << clk->refdiv_width) - 1);
- refdiv_val = val;
/* rate = 24000000 * (fbdiv + frac / (1<<24) ) / refdiv */
rate = 0;
tmp = 24000000 * fbdiv_val + (24000000 * frac_val) / (1 << 24);
rate += tmp;
- do_div(rate, refdiv_val);
- do_div(rate, postdiv1_val * postdiv2_val);
+ rate = div_u64(rate, val);
+ rate = div_u64(rate, postdiv1_val * postdiv2_val);
return rate;
}
--
2.45.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] clk: hisilicon: Remove unnecessary local variable
2024-08-01 10:36 [PATCH v2] clk: hisilicon: Remove unnecessary local variable Thorsten Blum
@ 2024-08-01 17:18 ` Uwe Kleine-König
2024-08-08 19:53 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2024-08-01 17:18 UTC (permalink / raw)
To: Thorsten Blum
Cc: mturquette, sboyd, erick.archer, gustavoars, christophe.jaillet,
linux-clk, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2289 bytes --]
Hello,
On Thu, Aug 01, 2024 at 12:36:16PM +0200, Thorsten Blum wrote:
> The local u64 variable refdiv_val has the same value as the local u32
> variable val and can be removed. Remove it and use val directly as the
> divisor to also remove the following Coccinelle/coccicheck warning
> reported by do_div.cocci:
>
> WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead
>
> Use the preferred div_u64() function instead of the do_div() macro.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
> Changes in v2:
> - Use div_u64() instead of do_div() as suggested by Stephen Boyd
> - Link to v1: https://lore.kernel.org/linux-kernel/20240710201844.710365-2-thorsten.blum@toblux.com/
> ---
> drivers/clk/hisilicon/clk-hi3559a.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clk/hisilicon/clk-hi3559a.c b/drivers/clk/hisilicon/clk-hi3559a.c
> index c79a94f6d9d2..8646e9d352ed 100644
> --- a/drivers/clk/hisilicon/clk-hi3559a.c
> +++ b/drivers/clk/hisilicon/clk-hi3559a.c
> @@ -407,7 +407,7 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
> unsigned long parent_rate)
> {
> struct hi3559av100_clk_pll *clk = to_pll_clk(hw);
> - u64 frac_val, fbdiv_val, refdiv_val;
> + u64 frac_val, fbdiv_val;
> u32 postdiv1_val, postdiv2_val;
> u32 val;
> u64 tmp, rate;
> @@ -435,14 +435,13 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
> val = readl_relaxed(clk->ctrl_reg2);
> val = val >> clk->refdiv_shift;
> val &= ((1 << clk->refdiv_width) - 1);
> - refdiv_val = val;
>
> /* rate = 24000000 * (fbdiv + frac / (1<<24) ) / refdiv */
> rate = 0;
> tmp = 24000000 * fbdiv_val + (24000000 * frac_val) / (1 << 24);
> rate += tmp;
> - do_div(rate, refdiv_val);
> - do_div(rate, postdiv1_val * postdiv2_val);
> + rate = div_u64(rate, val);
> + rate = div_u64(rate, postdiv1_val * postdiv2_val);
Without looking at the bigger context: Can postdiv1_val * postdiv2_val
overflow? (If this is a problem, fixing it justifies another patch, so
this concern shouldn't stop this patch from being accepted.)
Otherwise looks fine,
Acked-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] clk: hisilicon: Remove unnecessary local variable
2024-08-01 10:36 [PATCH v2] clk: hisilicon: Remove unnecessary local variable Thorsten Blum
2024-08-01 17:18 ` Uwe Kleine-König
@ 2024-08-08 19:53 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2024-08-08 19:53 UTC (permalink / raw)
To: Thorsten Blum, christophe.jaillet, erick.archer, gustavoars,
mturquette, u.kleine-koenig
Cc: linux-clk, linux-kernel, Thorsten Blum
Quoting Thorsten Blum (2024-08-01 03:36:16)
> The local u64 variable refdiv_val has the same value as the local u32
> variable val and can be removed. Remove it and use val directly as the
> divisor to also remove the following Coccinelle/coccicheck warning
> reported by do_div.cocci:
>
> WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead
>
> Use the preferred div_u64() function instead of the do_div() macro.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
Applied to clk-next
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-08 19:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-01 10:36 [PATCH v2] clk: hisilicon: Remove unnecessary local variable Thorsten Blum
2024-08-01 17:18 ` Uwe Kleine-König
2024-08-08 19:53 ` Stephen Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®