do_div() does a 64-by-32 division. Here the divisor is an
unsigned long which on some platforms is 64 bit wide. So use
div64_ul instead of do_div to avoid a possible truncation.
Eliminate the following coccicheck warnings:
./drivers/rtc/rtc-st-lpc.c:96:1-7: WARNING: do_div() does a 64-by-32
division, please consider using div64_ul instead.
./drivers/rtc/rtc-st-lpc.c:251:1-7: WARNING: do_div() does a 64-by-32
division, please consider using div64_ul instead.
Reported-by: Abaci Robot <[email protected]>
Signed-off-by: Yang Li <[email protected]>
---
drivers/rtc/rtc-st-lpc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
index bdb20f6..b6e169b 100644
--- a/drivers/rtc/rtc-st-lpc.c
+++ b/drivers/rtc/rtc-st-lpc.c
@@ -93,7 +93,7 @@ static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
spin_unlock_irqrestore(&rtc->lock, flags);
lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
- do_div(lpt, rtc->clkrate);
+ lpt = div64_ul(lpt, rtc->clkrate);
rtc_time64_to_tm(lpt, tm);
return 0;
@@ -248,7 +248,8 @@ static int st_rtc_probe(struct platform_device *pdev)
rtc->rtc_dev->ops = &st_rtc_ops;
rtc->rtc_dev->range_max = U64_MAX;
- do_div(rtc->rtc_dev->range_max, rtc->clkrate);
+ rtc->rtc_dev->range_max = div64_ul(rtc->rtc_dev->range_max,
+ rtc->clkrate);
ret = devm_rtc_register_device(rtc->rtc_dev);
if (ret) {
--
1.8.3.1