diff mbox series

[v1] pwm: microchip-core: fix incorrect comparison with max period

Message ID 20250122-pastor-fancied-0b993da2d2d2@spud (mailing list archive)
State New
Headers show
Series [v1] pwm: microchip-core: fix incorrect comparison with max period | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-1-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 122.83s
conchuod/patch-1-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 1093.10s
conchuod/patch-1-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 1338.24s
conchuod/patch-1-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 22.04s
conchuod/patch-1-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 23.41s
conchuod/patch-1-test-6 success .github/scripts/patches/tests/checkpatch.sh took 0.50s
conchuod/patch-1-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 43.94s
conchuod/patch-1-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.01s
conchuod/patch-1-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.57s
conchuod/patch-1-test-10 success .github/scripts/patches/tests/module_param.sh took 0.02s
conchuod/patch-1-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.04s
conchuod/patch-1-test-12 success .github/scripts/patches/tests/verify_signedoff.sh took 0.07s
bjorn/build-rv32-defconfig success build-rv32-defconfig
bjorn/build-rv64-clang-allmodconfig success build-rv64-clang-allmodconfig
bjorn/build-rv64-gcc-allmodconfig success build-rv64-gcc-allmodconfig
bjorn/build-rv64-nommu-k210-defconfig success build-rv64-nommu-k210-defconfig
bjorn/build-rv64-nommu-k210-virt success build-rv64-nommu-k210-virt
bjorn/checkpatch success checkpatch
bjorn/dtb-warn-rv64 success dtb-warn-rv64
bjorn/header-inline success header-inline
bjorn/kdoc success kdoc
bjorn/module-param success module-param
bjorn/verify-fixes success verify-fixes
bjorn/verify-signedoff success verify-signedoff

Commit Message

Conor Dooley Jan. 22, 2025, 2:42 p.m. UTC
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(-)

Comments

Uwe Kleine-König Jan. 23, 2025, 3:15 p.m. UTC | #1
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
diff mbox series

Patch

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;