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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240122081754.17058-4-Wenhua.Lin@unisoc.com>
Date: Mon, 22 Jan 2024 16:17:51 +0800
From: Wenhua Lin <Wenhua.Lin@...soc.com>
To: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
CC: Orson Zhai <orsonzhai@...il.com>,
        Baolin Wang
	<baolin.wang@...ux.alibaba.com>,
        Chunyan Zhang <zhang.lyra@...il.com>, <linux-pwm@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, wenhua lin
	<wenhua.lin1994@...il.com>,
        Wenhua Lin <Wenhua.Lin@...soc.com>,
        Xiongpeng Wu
	<xiongpeng.wu@...soc.com>,
        zhaochen su <zhaochen.su29@...il.com>,
        Zhaochen Su
	<Zhaochen.Su@...soc.com>,
        Xiaolong Wang <Xiaolong.Wang@...soc.com>
Subject: [PATCH 3/6] pwm: sprd: Optimize the calculation method of duty

Use DIV_ROUND_CLOSEST_ULL to avoid overflow and improve accuracy
when calculating duty.

Signed-off-by: Wenhua Lin <Wenhua.Lin@...soc.com>
---
 drivers/pwm/pwm-sprd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
index 411e91891c6d..22793e2b8707 100644
--- a/drivers/pwm/pwm-sprd.c
+++ b/drivers/pwm/pwm-sprd.c
@@ -156,7 +156,8 @@ static int sprd_pwm_config(struct sprd_pwm_chip *spc, struct pwm_device *pwm,
 	 * given settings (MOD and input clock).
 	 */
 	mod = spc->mod[pwm->hwpwm];
-	duty = duty_ns * mod / period_ns;
+	tmp = (u64)duty_ns * mod;
+	duty = DIV_ROUND_CLOSEST_ULL(tmp, period_ns);
 
 	tmp = (u64)chn->clk_rate * period_ns;
 	do_div(tmp, NSEC_PER_SEC);
-- 
2.17.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ