public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] imx/clk-pllv1: fix wrong do_div() usage
@ 2015-11-04  0:46 Nicolas Pitre
  2015-11-23  5:56 ` Shawn Guo
  2015-11-30 20:59 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Nicolas Pitre @ 2015-11-04  0:46 UTC (permalink / raw)
  To: Shawn Guo, Sascha Hauer, Michael Turquette; +Cc: linux-clk

do_div() is meant to be used with an unsigned dividend.

Signed-off-by: Nicolas Pitre <nico@linaro.org>

diff --git a/drivers/clk/imx/clk-pllv1.c b/drivers/clk/imx/clk-pllv1.c
index 8564e4342c..82fe3662b5 100644
--- a/drivers/clk/imx/clk-pllv1.c
+++ b/drivers/clk/imx/clk-pllv1.c
@@ -52,7 +52,7 @@ static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
 		unsigned long parent_rate)
 {
 	struct clk_pllv1 *pll = to_clk_pllv1(hw);
-	long long ll;
+	unsigned long long ull;
 	int mfn_abs;
 	unsigned int mfi, mfn, mfd, pd;
 	u32 reg;
@@ -94,16 +94,16 @@ static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
 	rate = parent_rate * 2;
 	rate /= pd + 1;
 
-	ll = (unsigned long long)rate * mfn_abs;
+	ull = (unsigned long long)rate * mfn_abs;
 
-	do_div(ll, mfd + 1);
+	do_div(ull, mfd + 1);
 
 	if (mfn_is_negative(pll, mfn))
-		ll = -ll;
+		ull = (rate * mfi) - ull;
+	else
+		ull = (rate * mfi) + ull;
 
-	ll = (rate * mfi) + ll;
-
-	return ll;
+	return ull;
 }
 
 static struct clk_ops clk_pllv1_ops = {

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

* Re: [PATCH] imx/clk-pllv1: fix wrong do_div() usage
  2015-11-04  0:46 [PATCH] imx/clk-pllv1: fix wrong do_div() usage Nicolas Pitre
@ 2015-11-23  5:56 ` Shawn Guo
  2015-11-30 20:59 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Shawn Guo @ 2015-11-23  5:56 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: Sascha Hauer, Michael Turquette, Stephen Boyd, linux-clk

Added Stephen.

On Tue, Nov 03, 2015 at 07:46:23PM -0500, Nicolas Pitre wrote:
> do_div() is meant to be used with an unsigned dividend.
> 
> Signed-off-by: Nicolas Pitre <nico@linaro.org>

Acked-by: Shawn Guo <shawnguo@kernel.org>

Mike, Stephen,

Can you please apply it for v4.4-rc?  Or I will queue it for v4.5-rc1.

Shawn

> 
> diff --git a/drivers/clk/imx/clk-pllv1.c b/drivers/clk/imx/clk-pllv1.c
> index 8564e4342c..82fe3662b5 100644
> --- a/drivers/clk/imx/clk-pllv1.c
> +++ b/drivers/clk/imx/clk-pllv1.c
> @@ -52,7 +52,7 @@ static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
>  		unsigned long parent_rate)
>  {
>  	struct clk_pllv1 *pll = to_clk_pllv1(hw);
> -	long long ll;
> +	unsigned long long ull;
>  	int mfn_abs;
>  	unsigned int mfi, mfn, mfd, pd;
>  	u32 reg;
> @@ -94,16 +94,16 @@ static unsigned long clk_pllv1_recalc_rate(struct clk_hw *hw,
>  	rate = parent_rate * 2;
>  	rate /= pd + 1;
>  
> -	ll = (unsigned long long)rate * mfn_abs;
> +	ull = (unsigned long long)rate * mfn_abs;
>  
> -	do_div(ll, mfd + 1);
> +	do_div(ull, mfd + 1);
>  
>  	if (mfn_is_negative(pll, mfn))
> -		ll = -ll;
> +		ull = (rate * mfi) - ull;
> +	else
> +		ull = (rate * mfi) + ull;
>  
> -	ll = (rate * mfi) + ll;
> -
> -	return ll;
> +	return ull;
>  }
>  
>  static struct clk_ops clk_pllv1_ops = {
> 
> 

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

* Re: [PATCH] imx/clk-pllv1: fix wrong do_div() usage
  2015-11-04  0:46 [PATCH] imx/clk-pllv1: fix wrong do_div() usage Nicolas Pitre
  2015-11-23  5:56 ` Shawn Guo
@ 2015-11-30 20:59 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2015-11-30 20:59 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: Shawn Guo, Sascha Hauer, Michael Turquette, linux-clk

On 11/03, Nicolas Pitre wrote:
> do_div() is meant to be used with an unsigned dividend.
> 
> Signed-off-by: Nicolas Pitre <nico@linaro.org>
> 

Applied to clk-fixes

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

end of thread, other threads:[~2015-11-30 20:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-04  0:46 [PATCH] imx/clk-pllv1: fix wrong do_div() usage Nicolas Pitre
2015-11-23  5:56 ` Shawn Guo
2015-11-30 20:59 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox