pwm: microchip-core: fix incorrect comparison with max period
Subsystems (4)
PATCH 1/1 pwm: microchip-core: fix incorrect comparison with max period
From: Conor Dooley <[email protected]>
In mchp_core_pwm_apply_locked(), if hw_period_steps is equal to its max, an error is reported and .apply fails. The max value is actually a permitted value however, and so this check can fail where multiple channels are enabled.
For example, the first channel to be configured requests a period that sets hw_period_steps to the maximum value, and when a second channel is enabled the driver reads hw_period_steps back from the hardware and finds it to be the maximum possible value, triggering the warning on a permitted value. The value to be avoided is 255 (PERIOD_STEPS_MAX + 1), as that will produce undesired behaviour, so test for greater than, rather than equal to.
---
CC: Conor Dooley <[email protected]>
CC: Daire McNamara <[email protected]>
CC: Uwe Kleine-König <[email protected]>
CC: Thierry Reding <[email protected]>
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- drivers/pwm/pwm-microchip-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/pwm-microchip-core.c +1 -1
@@ -327,7 +327,7 @@ static int mchp_core_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device ** mchp_core_pwm_calc_period(). * The period is locked and we cannot change this, so we abort. */ -if (hw_period_steps ==MCHPCOREPWM_PERIOD_STEPS_MAX ) +if (hw_period_steps >MCHPCOREPWM_PERIOD_STEPS_MAX )return -EINVAL ; prescale = hw_prescale;
Signature · 1 line
2.45.2
Uwe Kleine-König
maintainerHello Conor,
Quoted 15 lines · Conor Dooley
From: Conor Dooley <[email protected]>
In
mchp_core_pwm_apply_locked(), ifhw_period_stepsis equal to its max, an error is reported and .apply fails. The max value is actually a permitted value however, and so this check can fail where multiple channels are enabled.For example, the first channel to be configured requests a period that sets
hw_period_stepsto the maximum value, and when a second channel is enabled the driver readshw_period_stepsback from the hardware and finds it to be the maximum possible value, triggering the warning on a permitted value. The value to be avoided is 255 (PERIOD_STEPS_MAX+ 1), as that will produce undesired behaviour, so test for greater than, rather than equal to.
Quoted 3 lines
Fixes 2bf7ecf7b4ff ("pwm: add microchip soft ip corePWM driver")Signed-off-by Conor Dooley <[email protected]>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/fixes
which I intend to send to Linus next week.
Best regards
Uwe
This patch was applied to riscv/linux.git (fixes) by Uwe Kleine-König <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Uwe Kleine-König <[email protected]>:
Quoted 8 lines · On Wed, 22 Jan 2025 14:42:56 +0000 you wrote:
From: Conor Dooley <[email protected]>
In
mchp_core_pwm_apply_locked(), ifhw_period_stepsis equal to its max, an error is reported and .apply fails. The max value is actually a permitted value however, and so this check can fail where multiple channels are enabled.[...]
Here is the summary with links:
- [v1] pwm: microchip-core: fix incorrect comparison with max period
https://git.kernel.org/riscv/c/752b6e3af374
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html