public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: Linux PM <linux-pm@vger.kernel.org>, Felix Gu <ustc.gu@gmail.com>,
	William Breathitt Gray <wbg@kernel.org>,
	Judith Mendez <jm@ti.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] counter: ti-eqep: fix runtime PM leak in probe error path
Date: Wed, 29 Apr 2026 14:30:01 -0500	[thread overview]
Message-ID: <6b4840ea-fff9-4683-b595-e594435ee594@lechnology.com> (raw)
In-Reply-To: <20260418-ti-eqep-v2-1-2f803963c4fc@gmail.com>

On 4/17/26 11:08 AM, Felix Gu wrote:
> In ti_eqep_probe(), if devm_clk_get_enabled() fails, the function
> returns without cleaning up the runtime PM state.
> 
> Switch to devm functions to fix the problem and remove unneeded
> remove() callback.
> 
> Fixes: 0cf81c73e4c6 ("counter: ti-eqep: enable clock at probe")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> Changes in v2:
> - Switch to devm functions to fix David's comment.
> - Link to v1: https://lore.kernel.org/r/20260417-ti-eqep-v1-1-a7db4642d9d0@gmail.com
> ---
>  drivers/counter/ti-eqep.c | 33 +++++++++++++--------------------
>  1 file changed, 13 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c
> index d21c157e531a..08dc6d0ad5e4 100644
> --- a/drivers/counter/ti-eqep.c
> +++ b/drivers/counter/ti-eqep.c
> @@ -492,6 +492,11 @@ static const struct regmap_config ti_eqep_regmap16_config = {
>  	.max_register = QCPRDLAT,
>  };
>  
> +static void pm_put_sync(void *data)

This should have ti_eqep_ prefix in function name.

> +{
> +	pm_runtime_put_sync(data);
> +}
> +
>  static int ti_eqep_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -544,31 +549,20 @@ static int ti_eqep_probe(struct platform_device *pdev)
>  	 * parent PWMSS bus driver. On AM17xx, this comes from the PSC power
>  	 * domain.
>  	 */
> -	pm_runtime_enable(dev);
> +	err = devm_pm_runtime_enable(dev);
> +	if (err)
> +		return err;
> +
>  	pm_runtime_get_sync(dev);
> +	err = devm_add_action_or_reset(dev, pm_put_sync, dev);

I have no idea if this is OK or not. It seems like devm_pm_runtime_get_sync()
would exist already if it was OK. So that makes me think it is not OK.

I added PM mailing list to see if anyone can advise.

> +	if (err)
> +		return err;
>  
>  	clk = devm_clk_get_enabled(dev, NULL);
>  	if (IS_ERR(clk))
>  		return dev_err_probe(dev, PTR_ERR(clk), "failed to enable clock\n");
>  
> -	err = counter_add(counter);
> -	if (err < 0) {
> -		pm_runtime_put_sync(dev);
> -		pm_runtime_disable(dev);
> -		return err;
> -	}
> -
> -	return 0;
> -}
> -
> -static void ti_eqep_remove(struct platform_device *pdev)
> -{
> -	struct counter_device *counter = platform_get_drvdata(pdev);
> -	struct device *dev = &pdev->dev;
> -
> -	counter_unregister(counter);
> -	pm_runtime_put_sync(dev);
> -	pm_runtime_disable(dev);
> +	return devm_counter_add(dev, counter);

Using devm_counter_add() is not part of the fix, so should be in
a separate patch.

>  }
>  
>  static const struct of_device_id ti_eqep_of_match[] = {
> @@ -580,7 +574,6 @@ MODULE_DEVICE_TABLE(of, ti_eqep_of_match);
>  
>  static struct platform_driver ti_eqep_driver = {
>  	.probe = ti_eqep_probe,
> -	.remove = ti_eqep_remove,
>  	.driver = {
>  		.name = "ti-eqep-cnt",
>  		.of_match_table = ti_eqep_of_match,
> 
> ---
> base-commit: 452c3b1ea875276105ac90ba474f72b4cd9b77a2
> change-id: 20260417-ti-eqep-8efb9cc713ea
> 
> Best regards,


           reply	other threads:[~2026-04-29 19:30 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <20260418-ti-eqep-v2-1-2f803963c4fc@gmail.com>]

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=6b4840ea-fff9-4683-b595-e594435ee594@lechnology.com \
    --to=david@lechnology.com \
    --cc=jm@ti.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ustc.gu@gmail.com \
    --cc=wbg@kernel.org \
    /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