From: Lars-Peter Clausen Date: Tue, 22 Dec 2020 19:16:18 +0000 (+0100) Subject: iio: sc27xx_adc: Use DIV_ROUND_CLOSEST() instead of open-coding it X-Git-Tag: accepted/tizen/unified/20230118.172025~7876^2~112^2~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=138daca30ee9d9c0abc6a10f437dd38746c716e9;p=platform%2Fkernel%2Flinux-rpi.git 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. // @@ expression x, y; @@ -((x) + ((y) / 2)) / (y) +DIV_ROUND_CLOSEST(x, y) // Signed-off-by: Lars-Peter Clausen Acked-by: Chunyan Zhang Link: https://lore.kernel.org/r/20201222191618.3433-1-lars@metafoo.de Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c index aa32a1f..301cf66 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,