linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] rtc: st-lpc: Use div64_ul instead of do_div
@ 2021-11-18  3:25 Yang Li
  0 siblings, 0 replies; only message in thread
From: Yang Li @ 2021-11-18  3:25 UTC (permalink / raw)
  To: patrice.chotard
  Cc: a.zummo, alexandre.belloni, linux-arm-kernel, linux-rtc,
	linux-kernel, Yang Li

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 <abaci@linux.alibaba.com>
Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
---
 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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-18  3:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18  3:25 [PATCH -next] rtc: st-lpc: Use div64_ul instead of do_div Yang Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).