linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: ad4000: don't use shift_right()
@ 2025-07-02 13:23 David Lechner
  2025-07-02 14:09 ` Nuno Sá
  2025-07-02 14:46 ` Marcelo Schmitt
  0 siblings, 2 replies; 4+ messages in thread
From: David Lechner @ 2025-07-02 13:23 UTC (permalink / raw)
  To: Marcelo Schmitt, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Nuno Sá, Andy Shevchenko
  Cc: linux-iio, linux-kernel, David Lechner

Drop use of shift_right() macro for unsigned value. The shift_right()
macro is intended for signed values and is not needed for unsigned
values.

This was found by a static analysis tool [1].

Link: https://github.com/analogdevicesinc/linux/pull/2831/files#diff-c14a34a6492576d22e7192cc0f61ad0083190aeb627191596fe12462f0c6f21aR557 [1]
Signed-off-by: David Lechner <dlechner@baylibre.com>
---
 drivers/iio/adc/ad4000.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c
index 5609a7845b6f50b5818613170df6b234f8f0c496..fd3d79fca78581e51bb904d0bcfeda3d3663ea25 100644
--- a/drivers/iio/adc/ad4000.c
+++ b/drivers/iio/adc/ad4000.c
@@ -554,7 +554,7 @@ static void ad4000_fill_scale_tbl(struct ad4000_state *st,
 	val = mult_frac(st->vref_mv, MICRO, st->gain_milli);
 
 	/* Would multiply by NANO here but we multiplied by extra MILLI */
-	tmp2 = shift_right((u64)val * MICRO, scale_bits);
+	tmp2 = (u64)val * MICRO >> scale_bits;
 	tmp0 = div_s64_rem(tmp2, NANO, &tmp1);
 
 	/* Store scale for when span compression is disabled */

---
base-commit: 6742eff60460e77158d4f1b233f17e0345c9e66a
change-id: 20250702-iio-adc-ad4000-don-t-use-shift_right-bda6e41152b6

Best regards,
-- 
David Lechner <dlechner@baylibre.com>


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

* Re: [PATCH] iio: adc: ad4000: don't use shift_right()
  2025-07-02 13:23 [PATCH] iio: adc: ad4000: don't use shift_right() David Lechner
@ 2025-07-02 14:09 ` Nuno Sá
  2025-07-06 10:09   ` Jonathan Cameron
  2025-07-02 14:46 ` Marcelo Schmitt
  1 sibling, 1 reply; 4+ messages in thread
From: Nuno Sá @ 2025-07-02 14:09 UTC (permalink / raw)
  To: David Lechner, Marcelo Schmitt, Lars-Peter Clausen,
	Michael Hennerich, Jonathan Cameron, Nuno Sá,
	Andy Shevchenko
  Cc: linux-iio, linux-kernel

On Wed, 2025-07-02 at 08:23 -0500, David Lechner wrote:
> Drop use of shift_right() macro for unsigned value. The shift_right()
> macro is intended for signed values and is not needed for unsigned
> values.
> 
> This was found by a static analysis tool [1].
> 
> Link:
> https://github.com/analogdevicesinc/linux/pull/2831/files#diff-c14a34a6492576d22e7192cc0f61ad0083190aeb627191596fe12462f0c6f21aR557
>  [1]
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---

Reviewed-by: Nuno Sá <nuno.sa@analog.com>

>  drivers/iio/adc/ad4000.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c
> index
> 5609a7845b6f50b5818613170df6b234f8f0c496..fd3d79fca78581e51bb904d0bcfeda3d3663
> ea25 100644
> --- a/drivers/iio/adc/ad4000.c
> +++ b/drivers/iio/adc/ad4000.c
> @@ -554,7 +554,7 @@ static void ad4000_fill_scale_tbl(struct ad4000_state *st,
>  	val = mult_frac(st->vref_mv, MICRO, st->gain_milli);
>  
>  	/* Would multiply by NANO here but we multiplied by extra MILLI */
> -	tmp2 = shift_right((u64)val * MICRO, scale_bits);
> +	tmp2 = (u64)val * MICRO >> scale_bits;
>  	tmp0 = div_s64_rem(tmp2, NANO, &tmp1);
>  
>  	/* Store scale for when span compression is disabled */
> 
> ---
> base-commit: 6742eff60460e77158d4f1b233f17e0345c9e66a
> change-id: 20250702-iio-adc-ad4000-don-t-use-shift_right-bda6e41152b6
> 
> Best regards,

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

* Re: [PATCH] iio: adc: ad4000: don't use shift_right()
  2025-07-02 13:23 [PATCH] iio: adc: ad4000: don't use shift_right() David Lechner
  2025-07-02 14:09 ` Nuno Sá
@ 2025-07-02 14:46 ` Marcelo Schmitt
  1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Schmitt @ 2025-07-02 14:46 UTC (permalink / raw)
  To: David Lechner
  Cc: Marcelo Schmitt, Lars-Peter Clausen, Michael Hennerich,
	Jonathan Cameron, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel

On 07/02, David Lechner wrote:
> Drop use of shift_right() macro for unsigned value. The shift_right()
> macro is intended for signed values and is not needed for unsigned
> values.
> 
> This was found by a static analysis tool [1].
> 
> Link: https://github.com/analogdevicesinc/linux/pull/2831/files#diff-c14a34a6492576d22e7192cc0f61ad0083190aeb627191596fe12462f0c6f21aR557 [1]
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>

>  drivers/iio/adc/ad4000.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c
> index 5609a7845b6f50b5818613170df6b234f8f0c496..fd3d79fca78581e51bb904d0bcfeda3d3663ea25 100644
> --- a/drivers/iio/adc/ad4000.c
> +++ b/drivers/iio/adc/ad4000.c
> @@ -554,7 +554,7 @@ static void ad4000_fill_scale_tbl(struct ad4000_state *st,
>  	val = mult_frac(st->vref_mv, MICRO, st->gain_milli);
>  
>  	/* Would multiply by NANO here but we multiplied by extra MILLI */
> -	tmp2 = shift_right((u64)val * MICRO, scale_bits);
> +	tmp2 = (u64)val * MICRO >> scale_bits;
>  	tmp0 = div_s64_rem(tmp2, NANO, &tmp1);
>  
>  	/* Store scale for when span compression is disabled */
> 
> ---
> base-commit: 6742eff60460e77158d4f1b233f17e0345c9e66a
> change-id: 20250702-iio-adc-ad4000-don-t-use-shift_right-bda6e41152b6
> 
> Best regards,
> -- 
> David Lechner <dlechner@baylibre.com>
> 
> 

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

* Re: [PATCH] iio: adc: ad4000: don't use shift_right()
  2025-07-02 14:09 ` Nuno Sá
@ 2025-07-06 10:09   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-07-06 10:09 UTC (permalink / raw)
  To: Nuno Sá
  Cc: David Lechner, Marcelo Schmitt, Lars-Peter Clausen,
	Michael Hennerich, Nuno Sá, Andy Shevchenko, linux-iio,
	linux-kernel

On Wed, 02 Jul 2025 15:09:19 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Wed, 2025-07-02 at 08:23 -0500, David Lechner wrote:
> > Drop use of shift_right() macro for unsigned value. The shift_right()
> > macro is intended for signed values and is not needed for unsigned
> > values.
> > 
> > This was found by a static analysis tool [1].
> > 
> > Link:
> > https://github.com/analogdevicesinc/linux/pull/2831/files#diff-c14a34a6492576d22e7192cc0f61ad0083190aeb627191596fe12462f0c6f21aR557
> >  [1]
> > Signed-off-by: David Lechner <dlechner@baylibre.com>
> > ---  
> 
> Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Applied.
> 
> >  drivers/iio/adc/ad4000.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iio/adc/ad4000.c b/drivers/iio/adc/ad4000.c
> > index
> > 5609a7845b6f50b5818613170df6b234f8f0c496..fd3d79fca78581e51bb904d0bcfeda3d3663
> > ea25 100644
> > --- a/drivers/iio/adc/ad4000.c
> > +++ b/drivers/iio/adc/ad4000.c
> > @@ -554,7 +554,7 @@ static void ad4000_fill_scale_tbl(struct ad4000_state *st,
> >  	val = mult_frac(st->vref_mv, MICRO, st->gain_milli);
> >  
> >  	/* Would multiply by NANO here but we multiplied by extra MILLI */
> > -	tmp2 = shift_right((u64)val * MICRO, scale_bits);
> > +	tmp2 = (u64)val * MICRO >> scale_bits;
> >  	tmp0 = div_s64_rem(tmp2, NANO, &tmp1);
> >  
> >  	/* Store scale for when span compression is disabled */
> > 
> > ---
> > base-commit: 6742eff60460e77158d4f1b233f17e0345c9e66a
> > change-id: 20250702-iio-adc-ad4000-don-t-use-shift_right-bda6e41152b6
> > 
> > Best regards,  
> 


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

end of thread, other threads:[~2025-07-06 10:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-02 13:23 [PATCH] iio: adc: ad4000: don't use shift_right() David Lechner
2025-07-02 14:09 ` Nuno Sá
2025-07-06 10:09   ` Jonathan Cameron
2025-07-02 14:46 ` Marcelo Schmitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).