Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1174116 > unrolled thread

[PATCH 2/2] clk: iproc: fix bit manipulation arithmetic

Started byRay Jui <rjui@broadcom.com>
First post2015-06-29 23:30 +0200
Last post2015-06-29 23:40 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] clk: iproc: fix bit manipulation arithmetic Ray Jui <rjui@broadcom.com> - 2015-06-29 23:30 +0200
    Re: [PATCH 2/2] clk: iproc: fix bit manipulation arithmetic Ray Jui <rjui@broadcom.com> - 2015-06-29 23:40 +0200

#1174116 — [PATCH 2/2] clk: iproc: fix bit manipulation arithmetic

FromRay Jui <rjui@broadcom.com>
Date2015-06-29 23:30 +0200
Subject[PATCH 2/2] clk: iproc: fix bit manipulation arithmetic
Message-ID<pGOMQ-6LO-49@gated-at.bofh.it>
A 32-bit variable should be type casted to 64-bit before arithmetic
operation and assigning it to a 64-bit variable

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ray Jui <rjui@broadcom.com>
---
 drivers/clk/bcm/clk-iproc-pll.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/bcm/clk-iproc-pll.c b/drivers/clk/bcm/clk-iproc-pll.c
index a8d971b..2dda4e8 100644
--- a/drivers/clk/bcm/clk-iproc-pll.c
+++ b/drivers/clk/bcm/clk-iproc-pll.c
@@ -366,7 +366,7 @@ static unsigned long iproc_pll_recalc_rate(struct clk_hw *hw,
 	val = readl(pll->pll_base + ctrl->ndiv_int.offset);
 	ndiv_int = (val >> ctrl->ndiv_int.shift) &
 		bit_mask(ctrl->ndiv_int.width);
-	ndiv = ndiv_int << ctrl->ndiv_int.shift;
+	ndiv = (u64)ndiv_int << ctrl->ndiv_int.shift;
 
 	if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
 		val = readl(pll->pll_base + ctrl->ndiv_frac.offset);
@@ -374,7 +374,8 @@ static unsigned long iproc_pll_recalc_rate(struct clk_hw *hw,
 			bit_mask(ctrl->ndiv_frac.width);
 
 		if (ndiv_frac != 0)
-			ndiv = (ndiv_int << ctrl->ndiv_int.shift) | ndiv_frac;
+			ndiv = ((u64)ndiv_int << ctrl->ndiv_int.shift) |
+				ndiv_frac;
 	}
 
 	val = readl(pll->pll_base + ctrl->pdiv.offset);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1174123

FromRay Jui <rjui@broadcom.com>
Date2015-06-29 23:40 +0200
Message-ID<pGOWx-6XR-57@gated-at.bofh.it>
In reply to#1174116
+ Michael's new email

On 6/29/2015 2:30 PM, Ray Jui wrote:
> A 32-bit variable should be type casted to 64-bit before arithmetic
> operation and assigning it to a 64-bit variable
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Ray Jui <rjui@broadcom.com>
> ---
>  drivers/clk/bcm/clk-iproc-pll.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clk/bcm/clk-iproc-pll.c b/drivers/clk/bcm/clk-iproc-pll.c
> index a8d971b..2dda4e8 100644
> --- a/drivers/clk/bcm/clk-iproc-pll.c
> +++ b/drivers/clk/bcm/clk-iproc-pll.c
> @@ -366,7 +366,7 @@ static unsigned long iproc_pll_recalc_rate(struct clk_hw *hw,
>  	val = readl(pll->pll_base + ctrl->ndiv_int.offset);
>  	ndiv_int = (val >> ctrl->ndiv_int.shift) &
>  		bit_mask(ctrl->ndiv_int.width);
> -	ndiv = ndiv_int << ctrl->ndiv_int.shift;
> +	ndiv = (u64)ndiv_int << ctrl->ndiv_int.shift;
>  
>  	if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
>  		val = readl(pll->pll_base + ctrl->ndiv_frac.offset);
> @@ -374,7 +374,8 @@ static unsigned long iproc_pll_recalc_rate(struct clk_hw *hw,
>  			bit_mask(ctrl->ndiv_frac.width);
>  
>  		if (ndiv_frac != 0)
> -			ndiv = (ndiv_int << ctrl->ndiv_int.shift) | ndiv_frac;
> +			ndiv = ((u64)ndiv_int << ctrl->ndiv_int.shift) |
> +				ndiv_frac;
>  	}
>  
>  	val = readl(pll->pll_base + ctrl->pdiv.offset);
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web