1
linux/include/clocksource
Ken Sloat 56f45266df pwm: xilinx: Fix u32 overflow issue in 32-bit width PWM mode.
This timer HW supports 8, 16 and 32-bit timer widths. This
driver currently uses a u32 to store the max possible value
of the timer. However, statements perform addition of 2 in
xilinx_pwm_apply() when calculating the period_cycles and
duty_cycles values. Since priv->max is a u32, this will
result in an overflow to 1 which will not only be incorrect
but fail on range comparison. This results in making it
impossible to set the PWM in this timer mode.

There are two obvious solutions to the current problem:
1. Cast each instance where overflow occurs to u64.
2. Change priv->max from a u32 to a u64.

Solution #1 requires more code modifications, and leaves
opportunity to introduce similar overflows if other math
statements are added in the future. These may also go
undetected if running in non 32-bit timer modes.

Solution #2 is the much smaller and cleaner approach and
thus the chosen method in this patch.

This was tested on a Zynq UltraScale+ with multiple
instances of the PWM IP.

Signed-off-by: Ken Sloat <ksloat@designlinxhs.com>
Reviewed-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Sean Anderson <sean.anderson@seco.com>
Link: https://lore.kernel.org/r/SJ0P222MB0107490C5371B848EF04351CA1E19@SJ0P222MB0107.NAMP222.PROD.OUTLOOK.COM
Signed-off-by: Michal Simek <michal.simek@amd.com>
2024-06-03 13:07:56 +02:00
..
arm_arch_timer.h KVM: arm64: timers: Use CNTPOFF_EL2 to offset the physical timer 2023-03-30 19:01:09 +01:00
hyperv_timer.h clocksource: hyper-v: Adjust hv_read_tsc_page_tsc() to avoid special casing U64_MAX 2023-06-05 21:11:07 +02:00
pxa.h
samsung_pwm.h clocksource/drivers/samsung_pwm: Constify passed structure 2021-06-04 10:12:11 +02:00
timer-davinci.h clocksource/drivers/davinci: Add support for clockevents 2019-06-25 20:46:14 +02:00
timer-goldfish.h clocksource/drivers: Add a goldfish-timer clocksource 2022-04-11 11:48:01 +02:00
timer-riscv.h RISC-V: KVM: Add timer functionality 2021-10-04 16:07:16 +05:30
timer-ti-dm.h clocksource/drivers/timer-ti-dm: Make timer_get_irq static 2022-12-02 13:16:46 +01:00
timer-xilinx.h pwm: xilinx: Fix u32 overflow issue in 32-bit width PWM mode. 2024-06-03 13:07:56 +02:00