summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Dooley <conor.dooley@microchip.com>2025-01-22 14:42:56 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-02-17 11:36:42 +0100
commitc3ac0c29f48d2d934e215aecab3b11779c2f1112 (patch)
tree35edb77eb140cff7a2015bf7f1a11044f6fe7f63
parent15b5bb9012175ac9ed1d8481338d12cd9a6af43d (diff)
downloadlinux-c3ac0c29f48d2d934e215aecab3b11779c2f1112.tar.gz
linux-c3ac0c29f48d2d934e215aecab3b11779c2f1112.tar.bz2
linux-c3ac0c29f48d2d934e215aecab3b11779c2f1112.zip
pwm: microchip-core: fix incorrect comparison with max period
commit 752b6e3af374460a2de18f0c10bfa06bf844dbe8 upstream. 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. Fixes: 2bf7ecf7b4ff ("pwm: add microchip soft ip corePWM driver") Cc: stable@vger.kernel.org Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Link: https://lore.kernel.org/r/20250122-pastor-fancied-0b993da2d2d2@spud Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/pwm/pwm-microchip-core.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/pwm/pwm-microchip-core.c b/drivers/pwm/pwm-microchip-core.c
index c1f2287b8e97..12821b4bbf97 100644
--- a/drivers/pwm/pwm-microchip-core.c
+++ b/drivers/pwm/pwm-microchip-core.c
@@ -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;