lkml.org 
[lkml]   [2021]   [Nov]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH -next] rtc: st-lpc: Use div64_ul instead of do_div
Date
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
\
 
 \ /
  Last update: 2021-11-18 04:27    [W:0.044 / U:0.188 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site