Linux PWM subsystem development
 help / color / mirror / Atom feed
From: Andrew Davis <afd@ti.com>
To: "Lee Jones" <lee@kernel.org>,
	"Uwe Kleine-König" <ukleinek@kernel.org>,
	"Gokul Praveen" <g-praveen@ti.com>,
	"Philip, Avinash" <avinashphilip@ti.com>,
	"Thierry Reding" <thierry.reding@avionic-design.de>,
	"Vaibhav Bedia" <vaibhav.bedia@ti.com>,
	linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: <stable@vger.kernel.org>
Subject: Re: [PATCH v2 4/5] pwm: tiehrpwm: Enable runtime PM before registering PWM chip
Date: Mon, 23 Nov 2026 11:49:27 -0600	[thread overview]
Message-ID: <f9218622-c265-4302-997c-e60985201de6@ti.com> (raw)
In-Reply-To: <20261123075320.379664-5-lee@kernel.org>

On 11/23/26 1:52 AM, Lee Jones wrote:
> 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.
> 

To match what? The core of this change is moving pwmchip_add() after
pm_runtime_enable(), but in remove you switch clk and PM unwinding,
not pwm and PM unwinding. Both changes here are correct, but the
second is not explained in the commit message.

Would be better to have a patch before this one that switches clk_prepare(),
pm_runtime_enable(), and pwmchip_add() over to their DEVM equivalents. That
fixes the remove order issue, and removes the remove() function too.
Then this patch can simply move the pwmchip_add to after PM enable without
any other actions.

Andrew

> 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 <lee@kernel.org>
> ---
> 
> v1 => 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 *pdev)
>   		return ret;
>   	}
>   
> -	ret = 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);
>   
> +	ret = pwmchip_add(chip);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
> +		goto err_pm_disable;
> +	}
> +
>   	return 0;
>   
> -err_clk_unprepare:
> +err_pm_disable:
> +	pm_runtime_disable(&pdev->dev);
>   	clk_unprepare(pc->tbclk);
>   
>   	return ret;
> @@ -485,9 +486,9 @@ static void ehrpwm_pwm_remove(struct platform_device *pdev)
>   
>   	pwmchip_remove(chip);
>   
> -	clk_unprepare(pc->tbclk);
> -
>   	pm_runtime_disable(&pdev->dev);
> +
> +	clk_unprepare(pc->tbclk);
>   }
>   
>   static void ehrpwm_pwm_save_context(struct pwm_chip *chip)


  reply	other threads:[~2026-11-23 17:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  7:52 [PATCH v2 0/5] pwm: Fix various bugs reported by Sashiko Lee Jones
2026-11-23  7:52 ` [PATCH v2 1/5] pwm: mxs: Return early when disabling and fix error-path clock leak Lee Jones
2026-11-23  7:52 ` [PATCH v2 2/5] pwm: fsl-ftm: Enable ipg_clk around regcache_sync() during resume Lee Jones
2026-11-23  7:52 ` [PATCH v2 3/5] pwm: omap-dmtimer: Propagate get_pwm_status() errors in apply() Lee Jones
2026-11-23  7:52 ` [PATCH v2 4/5] pwm: tiehrpwm: Enable runtime PM before registering PWM chip Lee Jones
2026-11-23 17:49   ` Andrew Davis [this message]
2026-11-23  7:52 ` [PATCH v2 5/5] pwm: img: Unregister PWM chip before disabling runtime PM and clocks Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f9218622-c265-4302-997c-e60985201de6@ti.com \
    --to=afd@ti.com \
    --cc=avinashphilip@ti.com \
    --cc=g-praveen@ti.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=thierry.reding@avionic-design.de \
    --cc=ukleinek@kernel.org \
    --cc=vaibhav.bedia@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox