summaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2019-06-19 15:17:53 +0200
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2019-06-19 16:20:31 +0200
commitfedc459a3da35ecf171a1d6dd9f7f51fb452baf8 (patch)
tree26539ab12466d3a74b10e7a2704d205a26f47035 /drivers/rtc
parente32e60a2d5ecd8affc79f7da02d3479b4116579f (diff)
downloadlinux-stable-fedc459a3da35ecf171a1d6dd9f7f51fb452baf8.tar.gz
linux-stable-fedc459a3da35ecf171a1d6dd9f7f51fb452baf8.tar.bz2
linux-stable-fedc459a3da35ecf171a1d6dd9f7f51fb452baf8.zip
rtc: pcf2123: fix negative offset rounding
Using result = (value + divisor/2) / divisor is rounding values up and only works well for positive values. Instead use DIV_ROUND_CLOSEST which does the correct thing. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-pcf2123.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 3b314ce991e5..e8100af789ef 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -161,7 +161,7 @@ static int pcf2123_set_offset(struct device *dev, long offset)
else if (offset < OFFSET_STEP * -128)
reg = -128;
else
- reg = (s8)((offset + (OFFSET_STEP >> 1)) / OFFSET_STEP);
+ reg = DIV_ROUND_CLOSEST(offset, OFFSET_STEP);
/* choose fine offset only for odd values in the normal range */
if (reg & 1 && reg <= 63 && reg >= -64) {