lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1637205941-26223-1-git-send-email-yang.lee@linux.alibaba.com>
Date:   Thu, 18 Nov 2021 11:25:41 +0800
From:   Yang Li <yang.lee@...ux.alibaba.com>
To:     patrice.chotard@...s.st.com
Cc:     a.zummo@...ertech.it, alexandre.belloni@...tlin.com,
        linux-arm-kernel@...ts.infradead.org, linux-rtc@...r.kernel.org,
        linux-kernel@...r.kernel.org, Yang Li <yang.lee@...ux.alibaba.com>
Subject: [PATCH -next] rtc: st-lpc: Use div64_ul instead of do_div

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ