* [PATCH v1] pwm: microchip-core: fix incorrect comparison with max period
@ 2025-01-22 14:42 Conor Dooley
2025-01-23 15:15 ` Uwe Kleine-König
2025-02-03 19:15 ` patchwork-bot+linux-riscv
0 siblings, 2 replies; 3+ messages in thread
From: Conor Dooley @ 2025-01-22 14:42 UTC (permalink / raw)
To: linux-pwm
Cc: conor, Conor Dooley, stable, Daire McNamara,
Uwe Kleine-König, Thierry Reding, linux-riscv, linux-kernel
From: Conor Dooley <conor.dooley@microchip.com>
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>
---
CC: Conor Dooley <conor.dooley@microchip.com>
CC: Daire McNamara <daire.mcnamara@microchip.com>
CC: Uwe Kleine-König <ukleinek@kernel.org>
CC: Thierry Reding <thierry.reding@gmail.com>
CC: linux-riscv@lists.infradead.org
CC: linux-pwm@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
drivers/pwm/pwm-microchip-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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;
--
2.45.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] pwm: microchip-core: fix incorrect comparison with max period
2025-01-22 14:42 [PATCH v1] pwm: microchip-core: fix incorrect comparison with max period Conor Dooley
@ 2025-01-23 15:15 ` Uwe Kleine-König
2025-02-03 19:15 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2025-01-23 15:15 UTC (permalink / raw)
To: Conor Dooley
Cc: linux-pwm, Conor Dooley, stable, Daire McNamara, Thierry Reding,
linux-riscv, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1169 bytes --]
Hello Conor,
On Wed, Jan 22, 2025 at 02:42:56PM +0000, Conor Dooley wrote:
> From: Conor Dooley <conor.dooley@microchip.com>
>
> 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>
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] pwm: microchip-core: fix incorrect comparison with max period
2025-01-22 14:42 [PATCH v1] pwm: microchip-core: fix incorrect comparison with max period Conor Dooley
2025-01-23 15:15 ` Uwe Kleine-König
@ 2025-02-03 19:15 ` patchwork-bot+linux-riscv
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-02-03 19:15 UTC (permalink / raw)
To: Conor Dooley
Cc: linux-riscv, linux-pwm, conor.dooley, stable, daire.mcnamara,
ukleinek, thierry.reding, linux-kernel
Hello:
This patch was applied to riscv/linux.git (fixes)
by Uwe Kleine-König <ukleinek@kernel.org>:
On Wed, 22 Jan 2025 14:42:56 +0000 you wrote:
> From: Conor Dooley <conor.dooley@microchip.com>
>
> 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-03 19:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-22 14:42 [PATCH v1] pwm: microchip-core: fix incorrect comparison with max period Conor Dooley
2025-01-23 15:15 ` Uwe Kleine-König
2025-02-03 19:15 ` patchwork-bot+linux-riscv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox