All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it
@ 2020-12-22 19:16 Lars-Peter Clausen
  2020-12-23  5:39 ` Chunyan Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2020-12-22 19:16 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Peter Meerwald-Stadler, Orson Zhai, Baolin Wang, Chunyan Zhang,
	linux-iio, Lars-Peter Clausen

Use DIV_ROUND_CLOSEST() instead of open-coding it. This makes it more clear
what is going on for the casual reviewer.

Generated using the following the Coccinelle semantic patch.

// <smpl>
@@
expression x, y;
@@
-((x) + ((y) / 2)) / (y)
+DIV_ROUND_CLOSEST(x, y)
// </smpl>

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/iio/adc/sc27xx_adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index aa32a1f385e2..301cf66de695 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -307,7 +307,7 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
 
 	sc27xx_adc_volt_ratio(data, channel, scale, &numerator, &denominator);
 
-	return (volt * denominator + numerator / 2) / numerator;
+	return DIV_ROUND_CLOSEST(volt * denominator, numerator);
 }
 
 static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
-- 
2.20.1


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

* Re: [PATCH] iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it
  2020-12-22 19:16 [PATCH] iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it Lars-Peter Clausen
@ 2020-12-23  5:39 ` Chunyan Zhang
  2020-12-29 14:28   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Chunyan Zhang @ 2020-12-23  5:39 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Peter Meerwald-Stadler, Orson Zhai,
	Baolin Wang, linux-iio

On Wed, 23 Dec 2020 at 03:16, Lars-Peter Clausen <lars@metafoo.de> wrote:
>
> Use DIV_ROUND_CLOSEST() instead of open-coding it. This makes it more clear
> what is going on for the casual reviewer.
>
> Generated using the following the Coccinelle semantic patch.
>
> // <smpl>
> @@
> expression x, y;
> @@
> -((x) + ((y) / 2)) / (y)
> +DIV_ROUND_CLOSEST(x, y)
> // </smpl>
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>

Thanks,
Chunyan

> ---
>  drivers/iio/adc/sc27xx_adc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
> index aa32a1f385e2..301cf66de695 100644
> --- a/drivers/iio/adc/sc27xx_adc.c
> +++ b/drivers/iio/adc/sc27xx_adc.c
> @@ -307,7 +307,7 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
>
>         sc27xx_adc_volt_ratio(data, channel, scale, &numerator, &denominator);
>
> -       return (volt * denominator + numerator / 2) / numerator;
> +       return DIV_ROUND_CLOSEST(volt * denominator, numerator);
>  }
>
>  static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
> --
> 2.20.1
>

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

* Re: [PATCH] iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it
  2020-12-23  5:39 ` Chunyan Zhang
@ 2020-12-29 14:28   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2020-12-29 14:28 UTC (permalink / raw)
  To: Chunyan Zhang
  Cc: Lars-Peter Clausen, Peter Meerwald-Stadler, Orson Zhai,
	Baolin Wang, linux-iio

On Wed, 23 Dec 2020 13:39:24 +0800
Chunyan Zhang <zhang.lyra@gmail.com> wrote:

> On Wed, 23 Dec 2020 at 03:16, Lars-Peter Clausen <lars@metafoo.de> wrote:
> >
> > Use DIV_ROUND_CLOSEST() instead of open-coding it. This makes it more clear
> > what is going on for the casual reviewer.
> >
> > Generated using the following the Coccinelle semantic patch.
> >
> > // <smpl>
> > @@
> > expression x, y;
> > @@
> > -((x) + ((y) / 2)) / (y)
> > +DIV_ROUND_CLOSEST(x, y)
> > // </smpl>
> >
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>  
> 
> Acked-by: Chunyan Zhang <zhang.lyra@gmail.com>
Applied to the togreg branch of iio.git and pushed out as testing.

Thanks,

Jonathan

> 
> Thanks,
> Chunyan
> 
> > ---
> >  drivers/iio/adc/sc27xx_adc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
> > index aa32a1f385e2..301cf66de695 100644
> > --- a/drivers/iio/adc/sc27xx_adc.c
> > +++ b/drivers/iio/adc/sc27xx_adc.c
> > @@ -307,7 +307,7 @@ static int sc27xx_adc_convert_volt(struct sc27xx_adc_data *data, int channel,
> >
> >         sc27xx_adc_volt_ratio(data, channel, scale, &numerator, &denominator);
> >
> > -       return (volt * denominator + numerator / 2) / numerator;
> > +       return DIV_ROUND_CLOSEST(volt * denominator, numerator);
> >  }
> >
> >  static int sc27xx_adc_read_processed(struct sc27xx_adc_data *data,
> > --
> > 2.20.1
> >  


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

end of thread, other threads:[~2020-12-29 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22 19:16 [PATCH] iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it Lars-Peter Clausen
2020-12-23  5:39 ` Chunyan Zhang
2020-12-29 14:28   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.