Skip to content

Commit 752b6e3

Browse files
ConchuODUwe Kleine-König
authored andcommitted
pwm: microchip-core: fix incorrect comparison with max period
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: 2bf7ecf ("pwm: add microchip soft ip corePWM driver") Cc: [email protected] Signed-off-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/20250122-pastor-fancied-0b993da2d2d2@spud Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent e8c5979 commit 752b6e3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/pwm/pwm-microchip-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int mchp_core_pwm_apply_locked(struct pwm_chip *chip, struct pwm_device *
327327
* mchp_core_pwm_calc_period().
328328
* The period is locked and we cannot change this, so we abort.
329329
*/
330-
if (hw_period_steps == MCHPCOREPWM_PERIOD_STEPS_MAX)
330+
if (hw_period_steps > MCHPCOREPWM_PERIOD_STEPS_MAX)
331331
return -EINVAL;
332332

333333
prescale = hw_prescale;

0 commit comments

Comments
 (0)