提交 e81602b9 编写于 作者: U Uwe Kleine-König 提交者: Xie XiuQi

pwm: imx27: Fix overflow for bigger periods

stable inclusion
from stable-5.10.4
commit 7c4544a216e34c3867429585e532bec540c99751
bugzilla: 46903

--------------------------------

[ Upstream commit 1ce65396 ]

The second parameter of do_div is an u32 and NSEC_PER_SEC * prescale
overflows this for bigger periods. Assuming the usual pwm input clk rate
of 66 MHz this happens starting at requested period > 606060 ns.

Splitting the division into two operations doesn't loose any precision.
It doesn't need to be feared that c / NSEC_PER_SEC doesn't fit into the
unsigned long variable "duty_cycles" because in this case the assignment
above to period_cycles would already have been overflowing as
period >= duty_cycle and then the calculation is moot anyhow.

Fixes: aef1a379 ("pwm: imx27: Fix rounding behavior")
Signed-off-by: NUwe Kleine-König <uwe@kleine-koenig.org>
Tested-by: NJohannes Pointner <johannes.pointner@br-automation.com>
Signed-off-by: NThierry Reding <thierry.reding@gmail.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
上级 8f11a970
......@@ -235,8 +235,9 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
period_cycles /= prescale;
c = clkrate * state->duty_cycle;
do_div(c, NSEC_PER_SEC * prescale);
do_div(c, NSEC_PER_SEC);
duty_cycles = c;
duty_cycles /= prescale;
/*
* according to imx pwm RM, the real period value should be PERIOD
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册