From nobody Tue Nov 24 11:15:30 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420416; b=mLBrzJfqOdLMtTtglyo36QxIBtpTTt+POeqlkVybXsmgMWLnqATJ44wswElDb0k4kBsG gNflIidVqbvLNUyYxcWO6iF1VvnqjGse40eK0VjveoHMs4i9crUKRyBCCAyd0tbRGes1W jz1A3auhuKwPkn3aFG+4/WKxlxqksr/JlfyMHe8ORZsZMH0SvknhvQLF3Fq++j0qTWymJ A7L3MyhvussdOzkwLRr366djnfln4FOdVPTzxUU1e5Kp3AqNopB4RJmLvHHSkNTOQ8CaB ahDuQxBIkQSlqFSmTA2HMuhnwXJwptxqKT8qTRL74UXqnWd9aH6lvPgcUr+96zdxPsA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420416; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=1kgjCZJ8nKKX16FqAvd18yEVyO1lfwN7tM9UW2vB/JI=; b=t4fDDyzXRahlRSeo5bcdlKsK5myfMNGCc7bxEBzZGxREV98nnCKIjK/gQ+vsOdQoGIfR o1Z97Cx8kYVa5ewFkea00g7H1DfhRO/knj6rZFjIkCwiKsWLSN93ikpLaSPeryK2zVhvD lTRysbGleczeYh3YBEZUTUwFHCme7izAoPCafutFTo08jW2qKW8DtIAI0GiPkNGViGeIR /dHtNl70Ic0JFcZzdyNT3dfX69ci2k2L10pEcHIpGaFsKB/2KItZLYPruWBKERrQNV0qp 1XOddJah+P74QmvTw0FDBDNY5/hGjec86KQlyJiN/eGyDJiL1mPFAgHIv9PSVL8dnOA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cOYfqiaH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FDA4606A31A; Mon, 23 Nov 2026 07:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cOYfqiaH Received: by smtp.kernel.org (Postfix) with ESMTPSA id D04BE1F000EB; Mon, 23 Nov 2026 07:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420415; bh=1kgjCZJ8nKKX16FqAvd18yEVyO1lfwN7tM9UW2vB/JI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cOYfqiaHCqKz5KHb6ipksV+yDpdHw/eu3V3jjSWiWX/g+UlIlVu72IEHo9UqiD2Sm 9W6FIvamutDPvxfM/68kZo+125IP9JX7Pc5aMwNtw1CVFg+yHKlTVPyNprCZqHiSHG iTCQ2f5UZeKCTY9KzMnwi1AlwCIwD55yRRZlBtEOnw3ZW2qZO83oZrjTyuiiHUQDeS lwVNnuTcZfJ5hf4ES9HEMdWRuOzCtzZgPFCBFK5Jj0976i7FS3YBBqfLbCAp8grlBv qspDCks6NNr1/JrXPgzPdANK9F0U0dgZFlCsF7AdqnEGZf1+M0w0rnmHb0haMbS86r KiyIm1RRIgR+g== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Frank Li , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Geert Uytterhoeven , Chen Wang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20=28The=20Capable=20Hub=29?= , Shawn Guo , Rasmus Villemoes , Thierry Reding , linux-pwm@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 1/5] pwm: mxs: Return early when disabling and fix error-path clock leak Date: Mon, 23 Nov 2026 07:52:51 +0000 Message-ID: <20261123075320.379664-2-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075320.379664-1-lee@kernel.org> References: <20261123075320.379664-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When disabling a PWM channel (!state->enabled), the PWM core permits state->period to be zero. mxs_pwm_apply() currently falls through into the period and duty-cycle calculations even when !state->enabled, causing do_div(c, state->period) to divide by zero when state->period is zero. In addition, if the requested period exceeds the maximum divider (div >=3D PERIOD_CDIV_MAX) while the PWM channel is currently disabled, mxs_pwm_apply() returns -EINVAL without disabling and unpreparing mxs->clk. Handle the !state->enabled path upfront and return early, balance clk_prepare_enable() on the -EINVAL error path, and check pwm->state.enabled directly rather than calling the consumer helper pwm_is_enabled(). Fixes: bf29c2ff82fd ("pwm: mxs: Implement ->apply()") Closes: https://sashiko.dev/#/bug/linux-710f863f-6964-4e4f-990a-e5043dbc1a87 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Check pwm->state.enabled directly instead of calling the consumer helper pwm_is_enabled() (Uwe) - Drop Frank Li's Reviewed-by due to code changes drivers/pwm/pwm-mxs.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index e1a3df6549fc..768401b23dbb 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -56,20 +56,25 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct = pwm_device *pwm, unsigned long long c; unsigned int pol_bits; =20 + if (!state->enabled) { + if (pwm->state.enabled) { + writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR); + clk_disable_unprepare(mxs->clk); + } + return 0; + } + /* * If the PWM channel is disabled, make sure to turn on the * clock before calling clk_get_rate() and writing to the * registers. Otherwise, just keep it enabled. */ - if (!pwm_is_enabled(pwm)) { + if (!pwm->state.enabled) { ret =3D clk_prepare_enable(mxs->clk); if (ret) return ret; } =20 - if (!state->enabled && pwm_is_enabled(pwm)) - writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR); - rate =3D clk_get_rate(mxs->clk); while (1) { c =3D rate >> cdiv_shift[div]; @@ -78,8 +83,11 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct p= wm_device *pwm, if (c < PERIOD_PERIOD_MAX) break; div++; - if (div >=3D PERIOD_CDIV_MAX) + if (div >=3D PERIOD_CDIV_MAX) { + if (!pwm->state.enabled) + clk_disable_unprepare(mxs->clk); return -EINVAL; + } } =20 period_cycles =3D c; @@ -101,16 +109,12 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struc= t pwm_device *pwm, writel(PERIOD_PERIOD(period_cycles) | pol_bits | PERIOD_CDIV(div), mxs->base + PWM_PERIOD0 + pwm->hwpwm * 0x20); =20 - if (state->enabled) { - if (!pwm_is_enabled(pwm)) { - /* - * The clock was enabled above. Just enable - * the channel in the control register. - */ - writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + SET); - } - } else { - clk_disable_unprepare(mxs->clk); + if (!pwm->state.enabled) { + /* + * The clock was enabled above. Just enable + * the channel in the control register. + */ + writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + SET); } return 0; } --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 11:15:30 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420423; b=3u3JnnMeyzXq6J0uK0iKmjFOXrCCCKib93x1a56uVh0+jkbU3Jr8pa1D/9kGM9bsvp8E 0CLPbTvCWxSiXc4ln7rcMN48CXv34KtbxfRXdTTmq9wvWzDME0DOlxLkiqMWzu1UsBxxg oMuHKeV5pZzvDZO/VALUI2G2jKjyvlMaBSw3N4YJagDRFOo0eANshbMPtrncsNu3bltVx 7Zj8G7aD6cfDeObjQrAqOsbp6uQ2T5s1filLT4UM7ePdcdat00R+YQ7TOrN9oAdTlmNT5 8/RxH1gUCmGcgvyxMEydjE3/hYPy5MBc7L68gygUkMzhVWjKav3i5DhNjqaD3BVEeCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420423; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=GVv08OIoxkHUOqh5dxS1INjcKu3ezZkS2L1WZ71xYs4=; b=IZDLYpV9tR5qUgukTSO0ppDImhuIKiOYFsoQuLZPWHp7op4FwM6+4lgHrjd/JMuM66Sp mCSYf71uN1CIav8F3Y7Ot6cFPg4x3yO2EOnZlcuAVk/RPktfnAm8wghoges1k6LWLuN8x 1BsYxAot5uumxMaI8VfuN49vu6LP2OwPd5Cqq6IwTjqHcoS95CAsYrIrdlUHvVUbQjvy3 WrpuPiMPjk/s0qjIsj4xnC/wxYxNapqdJmqGXaZBs3XBH2peKuWV5Q/rcVcVr9BvEvtlB ayDJXqtdxtoAQMuRZUm22tg4ve3IQJcGsPy0Zrc0tuRufbwEZXaQqM0m6qYiFSVQ8eA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PqKKJDxQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72A76606A31A; Mon, 23 Nov 2026 07:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PqKKJDxQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 886E31F000C6; Mon, 23 Nov 2026 07:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420422; bh=GVv08OIoxkHUOqh5dxS1INjcKu3ezZkS2L1WZ71xYs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PqKKJDxQ/1w7p0ITSWdWVzt/ZO37JVsDTuC9DALpweTCVas6Lt/vNtNB8jqXRPps1 4WXQpAoQOSIVGfKg1IDj+Ueqqg92VIRrq09kwJCtuExfhhKEJP0QNL0XMqNXMxKhAv Eeb/BBVny9xkGQdjexJPixOy78kiPHy/QggnJ/WAWSmJoaG959CXCuOIYxu3Bvd/oV kvZnV3L3/8D+0LjRrajF+n7l/QV12x4PqaJmpYH2Sg+Qdad4JItv2zXuZ8nDCVCRUH AbdfB5x0cf4k8znK67XHZ+HImUbms3zr582QQh+Sjl7NA2rFADfVlVXcMSRQE7TRiV IU5sO29Tgql1w== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Xiubo Li , "shenwei.wang@nxp.com" , Thierry Reding , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 2/5] pwm: fsl-ftm: Enable ipg_clk around regcache_sync() during resume Date: Mon, 23 Nov 2026 07:52:52 +0000 Message-ID: <20261123075320.379664-3-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075320.379664-1-lee@kernel.org> References: <20261123075320.379664-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On SoCs with a dedicated IP interface clock (ipg_clk), register accesses require ipg_clk to be enabled in addition to the ftm_sys clock managed by regmap_mmio. In fsl_pwm_resume(), ipg_clk is only enabled inside the channel loop for channels with PWMF_REQUESTED set, so if no channels are currently requested, regcache_sync() writes to the hardware registers while ipg_clk is disabled. Enable ipg_clk around regcache_sync() in fsl_pwm_resume(), matching fsl_pwm_init(). Fixes: 82a9c55a2bb0 ("pwm: fsl-ftm: Added a dedicated IP interface clock") Closes: https://sashiko.dev/#/bug/linux-858851cf-55a9-4776-883c-69c05f3961f2 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Move clk_prepare_enable(fpc->ipg_clk) after the channel loop and add an explanatory comment (Uwe) drivers/pwm/pwm-fsl-ftm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c index 35406b2e1925..a73cea34dd82 100644 --- a/drivers/pwm/pwm-fsl-ftm.c +++ b/drivers/pwm/pwm-fsl-ftm.c @@ -501,6 +501,7 @@ static int fsl_pwm_resume(struct device *dev) { struct pwm_chip *chip =3D dev_get_drvdata(dev); struct fsl_pwm_chip *fpc =3D to_fsl_chip(chip); + int ret; int i; =20 for (i =3D 0; i < chip->npwm; i++) { @@ -518,10 +519,21 @@ static int fsl_pwm_resume(struct device *dev) clk_prepare_enable(fpc->clk[FSL_PWM_CLK_CNTEN]); } =20 + /* + * regmap_mmio only manages ftm_sys, whereas register accesses on SoCs + * with a dedicated IP interface clock also require ipg_clk. Enable + * ipg_clk around regcache_sync() in case no channels are requested. + */ + ret =3D clk_prepare_enable(fpc->ipg_clk); + if (ret) + return ret; + /* restore all registers from cache */ regcache_cache_only(fpc->regmap, false); regcache_sync(fpc->regmap); =20 + clk_disable_unprepare(fpc->ipg_clk); + return 0; } #endif --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 11:15:30 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420430; b=xqCLItjtyc/yhEPT1A4fAW4lgsu0jPsO5YvDrJYmId4tayoxT90JUuv8rfgYkJNaiFsS r+0gm6/VFo2BlA0IsJQL+mk9Ckq4DrQfyjAF5UtGkzvuXdvPfloO4MdO3+Zmts7KXlQw/ NlEm29rpuZBIzsQjvzZ5UFlM2RO9i2UJI+HnvMx0f+XCfUO4rGZDx+rD+19Gwk3CrLxwT h/FKbJgH2OX5wVfpvUnruliXwvraEoEWaxzJ1ocU5LxD/7K/PBI78ER15sZ6hVoWMefHN fvJLN/Tx3C1j/o/USt+b1DkLpXPesn9LvIuOe8mmMGzTnvLyQJ0Np11+YG6Ts/0xqrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420430; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=wCflPhiBOM2wwLKapiZUlRiMMbL5Bsuewp71SnPqdqw=; b=2m0wmcvv/Y8k+CMGCaD/i7bP3KrYD3FJYduWvuoaWBszoloImZkrkpiRNFEwFO+fFoU4 8L4D2maUOXqP5QaZ8g+bEedOr/Zda1DOuGd1+q5/nQc4NHvg1eaMRg+RimcEobi53pczE hRyngCe+1/gJwsBi6tH2rotdTvBmCKHMA8vBJxik81PRrSjaYuu4mU+LNRvq/xuTuQCH/ Pq+Hw7juahzJqlg8PkdN/IJ4DrTSdg4GpZFypcHWxLwMGeWy3I6IMamnOBXzXR+hzr1NG AZs5Wxfbv2B/a4pRDSojWTnUmA4V7qALro4nEHCiOGrBqXvEYQnDw2Z1SOUwjWKlsww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RD5yUT6h; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B92D2606A31E; Mon, 23 Nov 2026 07:53:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=RD5yUT6h Received: by smtp.kernel.org (Postfix) with ESMTPSA id 415871F000C0; Mon, 23 Nov 2026 07:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420430; bh=wCflPhiBOM2wwLKapiZUlRiMMbL5Bsuewp71SnPqdqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RD5yUT6hus4AHMI4YNvF8LI1wOEXsfLFEkxAT/PM8MlAWEtOzF67ThIgDxVJHcrds D6KuVV2wcNEdCsNyjNqskJL9mfFjnfPVeuKuxJO1VombSqBVa2sGQQ/jt3XJQKqMnm c/Wahjxub1JH/1flx0owuDWYf4BRaWpM/xHqa3VQ3twRwaRue0848QG94gv/Rvb4dl HcCBM17Q4tZYvtGwNqvtWuVXqJ+Axc2Awe93URgiKcDNaxnQVxy9Y5bQjU7IQKmAMG IFT0ruOtk27Agj1jpsP+A0TWq5y0fUZHzWF3SUpfa4dc06o1IUpTU9TxgYpFmxnd6C a4Zght/K/G1rA== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Geert Uytterhoeven , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig=20=28The=20Capable=20Hub=29?= , Chen Wang , Neil Armstrong , Joachim Eastwood , NeilBrown , Grant Erickson , Lokesh Vutla , Thierry Reding , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 3/5] pwm: omap-dmtimer: Propagate get_pwm_status() errors in apply() Date: Mon, 23 Nov 2026 07:52:53 +0000 Message-ID: <20261123075320.379664-4-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075320.379664-1-lee@kernel.org> References: <20261123075320.379664-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" omap->pdata->get_pwm_status() returns a signed int that can be a negative error code on runtime PM failure or invalid timer cookie. pwm_omap_dmtimer_is_enabled() and pwm_omap_dmtimer_polarity() store the return value in an unsigned u32 and test OMAP_TIMER_CTRL_ST (BIT(0)) and OMAP_TIMER_CTRL_SCPWM (BIT(7)), misinterpreting negative error codes (such as -EINVAL or -EACCES) as an enabled or inverted timer. Store the return value in a signed int and propagate negative error codes through to pwm_omap_dmtimer_apply(). Fixes: 6b28fb6f3ca3 ("pwm: omap-dmtimer: Implement .apply callback") Closes: https://sashiko.dev/#/bug/linux-f4782faa-466d-43a8-85d8-6d6181ee2243 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Propagate negative get_pwm_status() error codes through to pwm_omap_dmtimer_apply() (Uwe) drivers/pwm/pwm-omap-dmtimer.c | 54 +++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-omap-dmtimer.c b/drivers/pwm/pwm-omap-dmtimer.c index 51830a87275c..08d444b3928e 100644 --- a/drivers/pwm/pwm-omap-dmtimer.c +++ b/drivers/pwm/pwm-omap-dmtimer.c @@ -107,13 +107,15 @@ static void pwm_omap_dmtimer_start(struct pwm_omap_dm= timer_chip *omap) * pwm_omap_dmtimer_is_enabled() - Detect if the pwm is enabled. * @omap: Pointer to pwm omap dm timer chip * - * Return true if pwm is enabled else false. + * Return: 1 if pwm is enabled, 0 if disabled, or negative error code. */ -static bool pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap) +static int pwm_omap_dmtimer_is_enabled(struct pwm_omap_dmtimer_chip *omap) { - u32 status; + int status; =20 status =3D omap->pdata->get_pwm_status(omap->dm_timer); + if (status < 0) + return status; =20 return !!(status & OMAP_TIMER_CTRL_ST); } @@ -122,13 +124,15 @@ static bool pwm_omap_dmtimer_is_enabled(struct pwm_om= ap_dmtimer_chip *omap) * pwm_omap_dmtimer_polarity() - Detect the polarity of pwm. * @omap: Pointer to pwm omap dm timer chip * - * Return the polarity of pwm. + * Return: Polarity of pwm, or negative error code. */ static int pwm_omap_dmtimer_polarity(struct pwm_omap_dmtimer_chip *omap) { - u32 status; + int status; =20 status =3D omap->pdata->get_pwm_status(omap->dm_timer); + if (status < 0) + return status; =20 return !!(status & OMAP_TIMER_CTRL_SCPWM); } @@ -237,16 +241,21 @@ static int pwm_omap_dmtimer_config(struct pwm_chip *c= hip, * @chip: Pointer to PWM controller * @pwm: Pointer to PWM channel * @polarity: New pwm polarity to be set + * + * Return: 0 if successfully changed the polarity else appropriate error. */ -static void pwm_omap_dmtimer_set_polarity(struct pwm_chip *chip, - struct pwm_device *pwm, - enum pwm_polarity polarity) +static int pwm_omap_dmtimer_set_polarity(struct pwm_chip *chip, + struct pwm_device *pwm, + enum pwm_polarity polarity) { struct pwm_omap_dmtimer_chip *omap =3D to_pwm_omap_dmtimer_chip(chip); - bool enabled; + int enabled; =20 /* Disable the PWM before changing the polarity. */ enabled =3D pwm_omap_dmtimer_is_enabled(omap); + if (enabled < 0) + return enabled; + if (enabled) omap->pdata->stop(omap->dm_timer); =20 @@ -257,6 +266,8 @@ static void pwm_omap_dmtimer_set_polarity(struct pwm_ch= ip *chip, =20 if (enabled) pwm_omap_dmtimer_start(omap); + + return 0; } =20 /** @@ -272,22 +283,37 @@ static int pwm_omap_dmtimer_apply(struct pwm_chip *ch= ip, const struct pwm_state *state) { struct pwm_omap_dmtimer_chip *omap =3D to_pwm_omap_dmtimer_chip(chip); - int ret; + int enabled, polarity, ret; =20 - if (pwm_omap_dmtimer_is_enabled(omap) && !state->enabled) { + enabled =3D pwm_omap_dmtimer_is_enabled(omap); + if (enabled < 0) + return enabled; + + if (enabled && !state->enabled) { omap->pdata->stop(omap->dm_timer); return 0; } =20 - if (pwm_omap_dmtimer_polarity(omap) !=3D state->polarity) - pwm_omap_dmtimer_set_polarity(chip, pwm, state->polarity); + polarity =3D pwm_omap_dmtimer_polarity(omap); + if (polarity < 0) + return polarity; + + if (polarity !=3D state->polarity) { + ret =3D pwm_omap_dmtimer_set_polarity(chip, pwm, state->polarity); + if (ret) + return ret; + } =20 ret =3D pwm_omap_dmtimer_config(chip, pwm, state->duty_cycle, state->period); if (ret) return ret; =20 - if (!pwm_omap_dmtimer_is_enabled(omap) && state->enabled) { + enabled =3D pwm_omap_dmtimer_is_enabled(omap); + if (enabled < 0) + return enabled; + + if (!enabled && state->enabled) { omap->pdata->set_pwm(omap->dm_timer, state->polarity =3D=3D PWM_POLARITY_INVERSED, true, --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 11:15:30 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420438; b=piqfohJBqJYSmNY5/3KAi1DuI/jbFvOgbNh4owbKZQMO65FMHShlsacPCOEKVPaiYf5G QDgvrKpiPbwOa3GJYMHQTazNlsAdZFWUtyi6MQVNS/OXKlc7erEG3d7Lgx+FTleVeZXtZ vrm7UwWAo7yFlvT54DH9N3WDiaWg5kqFq1kU96fnQhWkNR2PdFbwoxVGNuV7v6IyqMCw+ fifu1cdV3SO4Uo4gOXO/QmqTrtYxi14BAyjUxTpeDR0OeelKaevUtkgNAXZjAjrMC9/DV O92B06Koq9ur6jDb/UXrXlnoKK6Z8wEmmQV+Yx/RE7pbYUZ+EPSGANa3UZpXtx+pQXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420438; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=nRgKwDlM71b06rNQ5/43AOR0ALDiZu7WP2FU65RRKH8=; b=qOrq4rwmZHDnPySd4jbAbFF0MT6jjBrs5C4hV7Ds4VhI0Pnry2ir1UJ9RYSD7pgpbOne PwNIB5jH1s5u234mly0Poj4KdxzFCilAZ9p3fAyONAVnV4NZc8EbMk8tN9m1PadVgVQED fe+8rLZILU0xY5cxLyHOUCOg6MGNlaYB8sZPu7P0782y6XigLPqmwmMfwC2pdr6VbiLAr mVJc6JAPjniMy6+ydmZN2nGnEaSR2+7HJwCtcJQ+KFfF+nO/DhjNCv4B1QsPqfgooXage VbLObmw/9Z/H0stWkrWhtPs8hWfjgrIzBdpqgP2En8EnlBp88AKIhEusiewdGbmjoHw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Z/N9+Gwn"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13154606A31A; Mon, 23 Nov 2026 07:53:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Z/N9+Gwn Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3D3E1F000C6; Mon, 23 Nov 2026 07:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420437; bh=nRgKwDlM71b06rNQ5/43AOR0ALDiZu7WP2FU65RRKH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Z/N9+GwnNxcNKOoFryRYQfqgWuIJC/am/3AtmtF/L0dfjdg4d8IQW7JkB/B7iCII7 n6muFq7YYsvyjo5dPrvIgvRqVS+x2jRLKhUKtumZbOEiwMETi2btmErEWUtxsdazFg PB2RN+Ezzy76L5Yqj+d5VFacfNx2Ri91ZLSahkwdSULp2YUh/YG63UqJUI0EMY036L ieQ6stJ2/oaNO7TfoD0gQio9oc7B/T2K6fAqOvGsnm6hh4UfrZ2Z/+0YPQL+Pdiy80 d9rXL3BhPVDoqic7BM5ze51YlwUjbcBayMWwFI8speR3luVRq2VhEKR1U3m35Qr2gi 9ZgwqKyrxPdUg== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Gokul Praveen , "Philip, Avinash" , Thierry Reding , Vaibhav Bedia , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 4/5] pwm: tiehrpwm: Enable runtime PM before registering PWM chip Date: Mon, 23 Nov 2026 07:52:54 +0000 Message-ID: <20261123075320.379664-5-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075320.379664-1-lee@kernel.org> References: <20261123075320.379664-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ehrpwm_pwm_probe() calls pwmchip_add() before setting driver data and enabling runtime PM. Because pwmchip_add() immediately exposes the PWM channels to consumers while runtime PM is still disabled on the initially RPM_SUSPENDED device, a consumer invoking ehrpwm_pwm_apply() before pm_runtime_enable() runs causes guard(pm_runtime_active) to fail with -EACCES without resuming the device and accesses unclocked MMIO registers. Set driver data and enable runtime PM before calling pwmchip_add(), disable runtime PM on the error path, and disable runtime PM before unpreparing tbclk in ehrpwm_pwm_remove() to match. Fixes: 19891b20e7c2 ("pwm: pwm-tiehrpwm: PWM driver support for EHRPWM") Closes: https://sashiko.dev/#/bug/linux-28b36a80-e4a9-4bb6-97bc-7ca02895570a Cc: stable@vger.kernel.org Signed-off-by: Lee Jones Reviewed-by: Andrew Davis --- v1 =3D> v2: - Clarify runtime PM state prior to pm_runtime_enable() in the commit description (Uwe) - Disable runtime PM before unpreparing tbclk in ehrpwm_pwm_remove() to match probe ordering (Uwe) drivers/pwm/pwm-tiehrpwm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/pwm/pwm-tiehrpwm.c b/drivers/pwm/pwm-tiehrpwm.c index e3407d0a1f7f..73fe2f91243d 100644 --- a/drivers/pwm/pwm-tiehrpwm.c +++ b/drivers/pwm/pwm-tiehrpwm.c @@ -461,18 +461,19 @@ static int ehrpwm_pwm_probe(struct platform_device *p= dev) return ret; } =20 - ret =3D pwmchip_add(chip); - if (ret < 0) { - dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); - goto err_clk_unprepare; - } - platform_set_drvdata(pdev, chip); pm_runtime_enable(&pdev->dev); =20 + ret =3D pwmchip_add(chip); + if (ret < 0) { + dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret); + goto err_pm_disable; + } + return 0; =20 -err_clk_unprepare: +err_pm_disable: + pm_runtime_disable(&pdev->dev); clk_unprepare(pc->tbclk); =20 return ret; @@ -485,9 +486,9 @@ static void ehrpwm_pwm_remove(struct platform_device *p= dev) =20 pwmchip_remove(chip); =20 - clk_unprepare(pc->tbclk); - pm_runtime_disable(&pdev->dev); + + clk_unprepare(pc->tbclk); } =20 static void ehrpwm_pwm_save_context(struct pwm_chip *chip) --=20 2.56.1.750.gf70dc682cf-goog From nobody Tue Nov 24 11:15:30 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795420445; b=ibgZElarEfGF2BRWCxRrxOx1fSnS6RKzNj/VCYt7kDzXkIBTQzEqPaJnYtIYmuQbcGzs z+iV+DLdD7HgudB8D2M2MmfFfgk3pv5SnaFyhzRgrg1GGN2GkS5Kcl3afihMcBvecp29y hhmH+g/yIx5Y2CMmMJJF3u84iSURdUgmJAwyAE14LsQ85nMlHDnTL8FtyBbHq703Bs/E3 4YNoBzN00aS1uulRgsyGtreRTlBXu3o7xfuBGFfxc5Dgh6N5U71jGu8gZQwDzkunt1Agn LSY1YmKjmVxW+xiGBQ/yfHhbZ6HFFBG0Nz0RCP2T7klHtQZyH4L4WUtocCvLIu9796g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795420445; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=GIMtN/V4X8FovWXLH2Jxatj9BkNalymkGlz/XfQQXtg=; b=i+8f+3pQ9IMC1mi/1/G+mc1B3iIV8RDmwigldSqMzfiz0EQ+kXOZC7aJCiu4cDuMMiRZ 462rIQnwRpTMnnZRyHvqU3IdpeBvK5SW1lZRLYTIC8udy+ObYmkPmCdaZl5dFtyzgjbsI Kbl5qRIQHGtzaEu+5Y/PYlcHLN1L78OjDHfXhtVFxu4+lxauOj5x0y3cZTgDnZwrkKkXe nzxXZbg5cWt9qgGL0262Ueu0SABaVSUNlqiS9XSgc80dIojR2f0EJOzXeqtuuwozCHXZB imQB10/knWHgy0IIwKtDx4BK9NOv9a9gsxpPG1L+K5H6a+bmVr9umWusE4bvw0fauWQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b0pn8mk0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 123CD606A31F; Mon, 23 Nov 2026 07:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b0pn8mk0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B19841F000C0; Mon, 23 Nov 2026 07:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795420444; bh=GIMtN/V4X8FovWXLH2Jxatj9BkNalymkGlz/XfQQXtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=b0pn8mk0uFIc/q3Id1+UdA2qRScX3yDUd+unk7T9M6P/joLxqIJQksIWEXPbg/3Br nmh8xdAh3XtFvK1iHkuK9FtguCaNu6yQf4O6JT3YYEon4w4TtMlOZwBxJ5YJPoQex0 6qq63jC/iI8ztjwM57hmcPN9yTKgECuqvetmq/RI1sf7gKUDzjBExLjy40jfvlPsZN 2niTifrxti9NielTUpRX95wh6pl2sWbMnPCUPJ/pSYyIiDQf+2ENk9PX/iyWB7b9OA LRwgFcSZ55Tk2qubRpQQwO3xBbBunEn0fBnF7QKFAYG6UYi7gKHwOR2C8/pqoWkc1o y2Gve1LaRDQNg== From: Lee Jones To: lee@kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Sai Masarapu , Vladimir Zapolskiy , Naidu Tellapati , Thierry Reding , Andrew Bresticker , linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v2 5/5] pwm: img: Unregister PWM chip before disabling runtime PM and clocks Date: Mon, 23 Nov 2026 07:52:55 +0000 Message-ID: <20261123075320.379664-6-lee@kernel.org> X-Mailer: git-send-email 2.56.1.750.gf70dc682cf-goog In-Reply-To: <20261123075320.379664-1-lee@kernel.org> References: <20261123075320.379664-1-lee@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" img_pwm_remove() disables runtime PM and gates the peripheral clocks via img_pwm_runtime_suspend() before calling pwmchip_remove(). While the PWM chip is still registered, a consumer can call img_pwm_apply(), where pm_runtime_resume_and_get() fails with -EACCES or img_pwm_disable() writes to unclocked registers after img_pwm_runtime_suspend() has gated the clocks. Call pwmchip_remove() before disabling runtime PM, clearing autosuspend, and suspending the device. Because chip and its private data are allocated with devm_pwmchip_alloc(), driver data remains valid for any pending runtime PM callbacks invoked during pm_runtime_disable() and img_pwm_runtime_suspend() until devres teardown runs after img_pwm_remove() returns. Fixes: 277bb6a29e00 ("pwm: Imagination Technologies PWM DAC driver") Closes: https://sashiko.dev/#/bug/linux-b06bab8d-dbf2-4ba2-9f5d-c5e141076abd Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- v1 =3D> v2: - Clear autosuspend in img_pwm_remove() and document why driver data remains valid for runtime PM callbacks after pwmchip_remove() (Uwe) drivers/pwm/pwm-img.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c index 91e0b19f0c08..7bf086b127c2 100644 --- a/drivers/pwm/pwm-img.c +++ b/drivers/pwm/pwm-img.c @@ -338,11 +338,12 @@ static void img_pwm_remove(struct platform_device *pd= ev) { struct pwm_chip *chip =3D platform_get_drvdata(pdev); =20 - pm_runtime_disable(&pdev->dev); - if (!pm_runtime_status_suspended(&pdev->dev)) - img_pwm_runtime_suspend(&pdev->dev); - pwmchip_remove(chip); + + pm_runtime_disable(&pdev->dev); + pm_runtime_dont_use_autosuspend(&pdev->dev); + if (!pm_runtime_status_suspended(&pdev->dev)) + img_pwm_runtime_suspend(&pdev->dev); } =20 #ifdef CONFIG_PM_SLEEP --=20 2.56.1.750.gf70dc682cf-goog