* [PATCH 0/8] pwm: Fix various bugs reported by Sashiko
@ 2026-11-05 14:38 Lee Jones
2026-11-05 14:38 ` [PATCH 1/8] pwm: tegra: Prevent 32-bit period truncation and division by zero Lee Jones
0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2026-11-05 14:38 UTC (permalink / raw)
To: lee
Cc: linux-kernel, Andrew Bresticker, Binbin Zhou, David Lechner,
Drew Fustini, Ezequiel Garcia, Fabio Estevam, Frank Li,
Grant Erickson, Huacai Chen, imx, Joachim Eastwood,
Jonathan Hunter, Juxin Gao, linux-arm-kernel, linux-pwm,
linux-tegra, Lokesh Vutla, Michael Hennerich, Mikko Perttunen,
Naidu Tellapati, Neil Armstrong, NeilBrown, Nuno Sá,
Pengutronix Kernel Team, Philip, Avinash, Rasmus Villemoes,
Sai Masarapu, Sandipan Patra, Sascha Hauer, Sergiu Cuciurean,
Shawn Guo, Shenwei Wang, Thierry Reding, Trevor Gamblin,
Uwe Kleine-König, Vaibhav Bedia, Vladimir Zapolskiy,
Xiubo Li
These issues were reported by Sashiko.
Lee Jones (8):
pwm: tegra: Prevent 32-bit period truncation and division by zero
pwm: mxs: Return early when disabling and fix error-path clock leak
pwm: loongson: Fix 32-bit control register truncation in
pwm_loongson_set_polarity()
pwm: axi-pwmgen: Enable clocks before accessing hardware registers in
probe()
pwm: fsl-ftm: Enable ipg_clk around regcache_sync() during resume
pwm: omap-dmtimer: Handle negative error codes from get_pwm_status()
pwm: tiehrpwm: Enable runtime PM before registering PWM chip
pwm: img: Unregister PWM chip before disabling runtime PM and clocks
drivers/pwm/pwm-axi-pwmgen.c | 20 ++++++++++----------
drivers/pwm/pwm-fsl-ftm.c | 7 +++++++
drivers/pwm/pwm-img.c | 8 ++++----
drivers/pwm/pwm-loongson.c | 2 +-
drivers/pwm/pwm-mxs.c | 32 ++++++++++++++++++--------------
drivers/pwm/pwm-omap-dmtimer.c | 8 ++++++--
drivers/pwm/pwm-tegra.c | 14 +++++++-------
drivers/pwm/pwm-tiehrpwm.c | 15 ++++++++-------
8 files changed, 61 insertions(+), 45 deletions(-)
Cc: Andrew Bresticker <abrestic@chromium.org>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Drew Fustini <dfustini@baylibre.com>
Cc: Ezequiel Garcia <ezequiel.garcia@imgtec.com>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Frank Li <Frank.Li@nxp.com>
Cc: Grant Erickson <marathon96@gmail.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: imx@lists.linux.dev
Cc: Joachim Eastwood <manabian@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Juxin Gao <gaojuxin@loongson.cn>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-pwm@vger.kernel.org
Cc: linux-tegra@vger.kernel.org
Cc: Lokesh Vutla <lokeshvutla@ti.com>
Cc: Michael Hennerich <michael.hennerich@analog.com>
Cc: Mikko Perttunen <mperttunen@nvidia.com>
Cc: Naidu Tellapati <naidu.tellapati@gmail.com>
Cc: Neil Armstrong <neil.armstrong@linaro.org>
Cc: NeilBrown <neil@brown.name>
Cc: "Nuno Sá" <nuno.sa@analog.com>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: "Philip, Avinash" <avinashphilip@ti.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sai Masarapu <Sai.Masarapu@imgtec.com>
Cc: Sandipan Patra <spatra@nvidia.com>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Shenwei Wang <shenwei.wang@nxp.com>
Cc: Thierry Reding <thierry.reding@kernel.org>
Cc: Trevor Gamblin <tgamblin@baylibre.com>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: Vaibhav Bedia <vaibhav.bedia@ti.com>
Cc: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Cc: Xiubo Li <Li.Xiubo@freescale.com>
--
2.56.0.398.g882cbad275-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/8] pwm: tegra: Prevent 32-bit period truncation and division by zero
2026-11-05 14:38 [PATCH 0/8] pwm: Fix various bugs reported by Sashiko Lee Jones
@ 2026-11-05 14:38 ` Lee Jones
2026-11-05 15:46 ` Uwe Kleine-König
0 siblings, 1 reply; 3+ messages in thread
From: Lee Jones @ 2026-11-05 14:38 UTC (permalink / raw)
To: lee, Thierry Reding, Uwe Kleine-König, Jonathan Hunter,
Mikko Perttunen, Sascha Hauer, Sandipan Patra, linux-pwm,
linux-tegra, linux-kernel
Cc: stable
tegra_pwm_apply() passes the 64-bit state->duty_cycle and state->period
values into tegra_pwm_config(), which accepts signed 32-bit int
parameters and performs DIV_ROUND_CLOSEST_ULL(c, period_ns) before
validating period_ns against pc->min_period_ns. If a consumer requests
a period that is a non-zero multiple of 2^32 nanoseconds, period_ns
truncates to zero and triggers a divide-by-zero panic.
Widen duty_ns and period_ns to u64 and validate that period_ns lies
within [pc->min_period_ns, U32_MAX] prior to dividing by period_ns.
Fixes: 1d7796bdb63a ("pwm: tegra: Support dynamic clock frequency configuration")
Fixes: fd3ddd4355c0 ("pwm: tegra: Implement .apply() callback")
Closes: https://sashiko.dev/#/bug/linux-5c5b97d6-4da6-4d06-9dc7-957419dcd832
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pwm/pwm-tegra.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
index 5cdbe120ba2d..f99ae2b3a276 100644
--- a/drivers/pwm/pwm-tegra.c
+++ b/drivers/pwm/pwm-tegra.c
@@ -138,7 +138,7 @@ static inline void tegra_pwm_writel(struct pwm_device *pwm, unsigned int offset,
}
static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
- int duty_ns, int period_ns)
+ u64 duty_ns, u64 period_ns)
{
struct tegra_pwm_chip *pc = to_tegra_pwm_chip(chip);
unsigned long long c = duty_ns;
@@ -146,6 +146,12 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
u32 val = 0;
int err;
+ /*
+ * min period = max clock limit / TEGRA_PWM_DEPTH
+ */
+ if (period_ns < pc->min_period_ns || period_ns > U32_MAX)
+ return -EINVAL;
+
/*
* Convert from duty_ns / period_ns to a fixed number of duty ticks
* per TEGRA_PWM_DEPTH cycles and make sure to round to the
@@ -156,12 +162,6 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
val = (u32)c << TEGRA_PWM_DUTY_SHIFT;
- /*
- * min period = max clock limit / TEGRA_PWM_DEPTH
- */
- if (period_ns < pc->min_period_ns)
- return -EINVAL;
-
/*
* Compute the prescaler value for which TEGRA_PWM_DEPTH
* cycles at the PWM clock rate will take period_ns nanoseconds.
Cc: Sandipan Patra <spatra@nvidia.com>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>
--
2.56.0.398.g882cbad275-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/8] pwm: tegra: Prevent 32-bit period truncation and division by zero
2026-11-05 14:38 ` [PATCH 1/8] pwm: tegra: Prevent 32-bit period truncation and division by zero Lee Jones
@ 2026-11-05 15:46 ` Uwe Kleine-König
0 siblings, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2026-11-05 15:46 UTC (permalink / raw)
To: Lee Jones
Cc: Thierry Reding, Jonathan Hunter, Mikko Perttunen, Sascha Hauer,
Sandipan Patra, linux-pwm, linux-tegra, linux-kernel, stable
[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]
Hello Lee,
On Thu, Nov 05, 2026 at 02:38:03PM +0000, Lee Jones wrote:
> tegra_pwm_apply() passes the 64-bit state->duty_cycle and state->period
> values into tegra_pwm_config(), which accepts signed 32-bit int
> parameters and performs DIV_ROUND_CLOSEST_ULL(c, period_ns) before
> validating period_ns against pc->min_period_ns. If a consumer requests
> a period that is a non-zero multiple of 2^32 nanoseconds, period_ns
> truncates to zero and triggers a divide-by-zero panic.
>
> Widen duty_ns and period_ns to u64 and validate that period_ns lies
> within [pc->min_period_ns, U32_MAX] prior to dividing by period_ns.
>
> Fixes: 1d7796bdb63a ("pwm: tegra: Support dynamic clock frequency configuration")
> Fixes: fd3ddd4355c0 ("pwm: tegra: Implement .apply() callback")
> Closes: https://sashiko.dev/#/bug/linux-5c5b97d6-4da6-4d06-9dc7-957419dcd832
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
This is already addressed in
9ad5602d4943 ("pwm: tegra: Fix value discarding for duty and period")
which is next-20261102 and later.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-05 15:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 14:38 [PATCH 0/8] pwm: Fix various bugs reported by Sashiko Lee Jones
2026-11-05 14:38 ` [PATCH 1/8] pwm: tegra: Prevent 32-bit period truncation and division by zero Lee Jones
2026-11-05 15:46 ` Uwe Kleine-König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox