linux-stable/drivers/pwm
Uwe Kleine-König 8aa69de3d0 pwm: lpc18xx: Fix period handling
[ Upstream commit 8933d30c5f ]

The calculation:

	val = (u64)NSEC_PER_SEC * LPC18XX_PWM_TIMER_MAX;
	do_div(val, lpc18xx_pwm->clk_rate);
	lpc18xx_pwm->max_period_ns = val;

is bogus because with NSEC_PER_SEC = 1000000000,
LPC18XX_PWM_TIMER_MAX = 0xffffffff and clk_rate < NSEC_PER_SEC this
overflows the (on lpc18xx (i.e. ARM32) 32 bit wide) unsigned int
.max_period_ns. This results (dependant of the actual clk rate) in an
arbitrary limitation of the maximal period.  E.g. for clkrate =
333333333 (Hz) we get max_period_ns = 9 instead of 12884901897.

So make .max_period_ns an u64 and pass period and duty as u64 to not
discard relevant digits. And also make use of mul_u64_u64_div_u64()
which prevents all overflows assuming clk_rate < NSEC_PER_SEC.

Fixes: 841e6f90bb ("pwm: NXP LPC18xx PWM/SCT driver")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-17 15:14:21 +02:00
..
Kconfig pwm: sunplus-pwm: Add Sunplus SoC SP7021 PWM Driver 2022-04-22 18:34:24 +02:00
Makefile pwm: sunplus-pwm: Add Sunplus SoC SP7021 PWM Driver 2022-04-22 18:34:24 +02:00
core.c pwm: Changes for v5.17-rc1 2022-01-20 13:25:01 +02:00
pwm-ab8500.c pwm: ab8500: Simplify using devm_pwmchip_add() 2021-09-02 21:38:40 +02:00
pwm-atmel-hlcdc.c pwm: atmel-hlcdc: Don't check the return code of pwmchip_remove() 2021-09-02 21:38:49 +02:00
pwm-atmel-tcb.c pwm: atmel-tcb: Make atmel_tcb_divisors static 2022-04-22 18:49:42 +02:00
pwm-atmel.c pwm: atmel: Remove redundant initialization of variable timeout 2022-02-24 13:54:05 +01:00
pwm-bcm-iproc.c
pwm-bcm-kona.c pwm: bcm-kona: Implement .apply() callback 2022-02-24 13:53:13 +01:00
pwm-bcm2835.c
pwm-berlin.c pwm: berlin: Ensure configuring period and duty_cycle isn't wrongly skipped 2021-07-08 16:09:17 +02:00
pwm-brcmstb.c pwm: brcmstb: Remove useless locking 2022-02-24 14:46:24 +01:00
pwm-clps711x.c pwm: clps71xx: Implement .apply() callback 2022-04-22 18:52:30 +02:00
pwm-crc.c
pwm-cros-ec.c pwm: pwm-cros-ec: Add channel type support 2022-05-20 16:40:01 +02:00
pwm-dwc.c
pwm-ep93xx.c pwm: ep93xx: Simplify using devm_pwmchip_add() 2021-09-02 21:38:41 +02:00
pwm-fsl-ftm.c pwm: fsl-ftm: Simplify using devm_pwmchip_add() 2021-09-02 21:38:41 +02:00
pwm-hibvt.c pwm: hibvt: Disable the clock only after the PWM was unregistered 2021-09-02 21:38:37 +02:00
pwm-img.c pwm: img: Rename variable pointing to driver private data 2022-02-02 17:06:05 +01:00
pwm-imx-tpm.c pwm: imx-tpm: Don't check the return code of pwmchip_remove() 2021-09-02 21:38:52 +02:00
pwm-imx1.c pwm: imx1: Implement .apply callback 2022-02-02 17:05:19 +01:00
pwm-imx27.c pwm: imx27: Simplify using devm_pwmchip_add() 2021-09-02 21:38:42 +02:00
pwm-intel-lgm.c pwm: intel-lgm: Simplify using devm_pwmchip_add() 2021-09-02 21:38:42 +02:00
pwm-iqs620a.c pwm: iqs620a: Simplify using devm_pwmchip_add() 2021-09-02 21:38:43 +02:00
pwm-jz4740.c pwm: jz4740: Add support for X1000 SoC 2022-02-24 14:37:21 +01:00
pwm-keembay.c pwm: keembay: Simplify using devm_pwmchip_add() 2021-09-02 21:38:44 +02:00
pwm-lp3943.c pwm: lp3943: Implement .apply() callback 2022-04-22 18:43:09 +02:00
pwm-lpc18xx-sct.c pwm: lpc18xx: Fix period handling 2022-08-17 15:14:21 +02:00
pwm-lpc32xx.c pwm: lpc32xx: Implement .apply() callback 2022-05-20 16:29:01 +02:00
pwm-lpss-pci.c
pwm-lpss-platform.c
pwm-lpss.c
pwm-lpss.h
pwm-mediatek.c pwm: mediatek: Implement .apply() callback 2022-05-20 16:29:16 +02:00
pwm-meson.c pwm: meson: Drop always false check from .apply() 2022-02-01 08:38:10 +01:00
pwm-mtk-disp.c pwm: mtk-disp: Implement atomic API .get_state() 2021-09-02 22:27:46 +02:00
pwm-mxs.c pwm: mxs: Simplify using devm_pwmchip_add() 2021-09-02 21:38:45 +02:00
pwm-ntxec.c pwm: ntxec: Simplify using devm_pwmchip_add() 2021-09-02 21:38:46 +02:00
pwm-omap-dmtimer.c pwm: omap-dmtimer: Don't check the return code of pwmchip_remove() 2021-09-02 21:38:52 +02:00
pwm-pca9685.c pwm: pca9685: Reset OFF/ON registers to POR value 2022-02-24 14:01:18 +01:00
pwm-pxa.c pwm: pxa: Implement .apply() callback 2022-02-02 18:03:05 +01:00
pwm-raspberrypi-poe.c pwm: raspberrypi-poe: Fix endianness in firmware struct 2022-04-22 18:50:51 +02:00
pwm-rcar.c pwm: rcar: Simplify multiplication/shift logic 2022-02-24 15:14:56 +01:00
pwm-renesas-tpu.c pwm: renesas-tpu: Improve precision of period and duty_cycle calculation 2022-05-20 16:18:40 +02:00
pwm-rockchip.c pwm: rockchip: Unprepare clocks only after the PWM was unregistered 2021-09-02 21:38:38 +02:00
pwm-samsung.c pwm: samsung: Implement .apply() callback 2022-05-20 15:59:34 +02:00
pwm-sifive.c pwm: sifive: Shut down hardware only after pwmchip_remove() completed 2022-08-17 15:14:21 +02:00
pwm-sl28cpld.c pwm: sl28cpld: Simplify using devm_pwmchip_add() 2021-09-02 21:38:47 +02:00
pwm-spear.c pwm: spear: Ensure configuring period and duty_cycle isn't wrongly skipped 2021-07-08 16:08:38 +02:00
pwm-sprd.c pwm: sprd: Ensure configuring period and duty_cycle isn't wrongly skipped 2021-07-08 16:08:08 +02:00
pwm-sti.c pwm: sti: Implement .apply() callback 2022-05-20 16:28:18 +02:00
pwm-stm32-lp.c pwm: stm32-lp: Simplify using devm_pwmchip_add() 2021-09-02 21:38:47 +02:00
pwm-stm32.c
pwm-stmpe.c pwm: stmpe: Implement .apply() callback 2022-05-20 16:28:35 +02:00
pwm-sun4i.c pwm-sun4i: Calculate the delay without rounding down to jiffies 2022-04-22 17:44:48 +02:00
pwm-sunplus.c pwm: sunplus-pwm: Add Sunplus SoC SP7021 PWM Driver 2022-04-22 18:34:24 +02:00
pwm-tegra.c pwm: tegra: Implement .apply() callback 2022-05-20 16:28:49 +02:00
pwm-tiecap.c pwm: tiecap: Simplify using devm_pwmchip_add() 2021-09-02 21:38:48 +02:00
pwm-tiehrpwm.c pwm: tiehrpwm: Implement .apply() callback 2022-02-24 13:52:59 +01:00
pwm-twl-led.c pwm: twl-led: Implement .apply() callback 2022-05-20 16:34:54 +02:00
pwm-twl.c pwm: twl: Implement .apply() callback 2021-11-17 17:12:42 +01:00
pwm-visconti.c pwm: visconti: Simplify using devm_pwmchip_add() 2021-11-05 11:51:41 +01:00
pwm-vt8500.c pwm: vt8500: Rename variable pointing to driver private data 2022-02-24 14:35:20 +01:00
pwm-xilinx.c pwm: Add support for Xilinx AXI Timer 2022-04-22 18:30:44 +02:00
sysfs.c