iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it
Subsystems (2)
PATCH 1/1 iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it
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>
--- drivers/iio/adc/sc27xx_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/sc27xx_adc.c +1 -1
@@ -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,
Signature · 1 line
2.20.1
Quoted 14 lines · 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;
@@(quoted diff) +1
-1-((x) + ((y) / 2)) / (y) +DIV_ROUND_CLOSEST(x, y)// </smpl>
Quoted 1 line
Signed-off-by Lars-Peter Clausen <[email protected]>
Thanks,
Chunyan
Quoted 20 lines
--- drivers/iio/adc/sc27xx_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/sc27xx_adc.c +1
-2@@ -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
Jonathan Cameron
maintainerQuoted 15 lines · On Wed, 23 Dec 2020 13:39:24 +0800 Chunyan Zhang <[email protected]> wrote:
Quoted 14 lines · 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;
@@(quoted diff) +1
-1-((x) + ((y) / 2)) / (y) +DIV_ROUND_CLOSEST(x, y)// </smpl>
Quoted 3 lines
Quoted 1 line
Signed-off-by Lars-Peter Clausen <[email protected]>Acked-by Chunyan Zhang <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing.
Thanks,
Jonathan
Quoted 24 lines
Thanks,
ChunyanQuoted 20 lines
--- drivers/iio/adc/sc27xx_adc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/sc27xx_adc.c +1
-2@@ -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