Commit 2b2922de authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Zheng Zengkai
Browse files

pwm: iqs620a: Fix overflow and optimize calculations



stable inclusion
from stable-5.10.20
commit e47685ec4cb8d59f8706da532ef58b403871b534
bugzilla: 50608

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

[ Upstream commit 72d6b245 ]

If state->duty_cycle is 0x100000000000000, the previous calculation of
duty_scale overflows and yields a duty cycle ratio of 0% instead of
100%. Fix this by clamping the requested duty cycle to the maximal
possible duty cycle first. This way it is possible to use a native
integer division instead of a (depending on the architecture) more
expensive 64bit division.

With this change in place duty_scale cannot be bigger than 256 which
allows to simplify the calculation of duty_val.

Fixes: 6f0841a8 ("pwm: Add support for Azoteq IQS620A PWM generator")
Tested-by: default avatarJeff LaBundy <jeff@labundy.com>
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarChen Jun <chenjun102@huawei.com>
Acked-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent d2c29dca
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment