* Re: [PATCH v2] counter: ti-eqep: fix runtime PM leak in probe error path
[not found] <20260418-ti-eqep-v2-1-2f803963c4fc@gmail.com>
@ 2026-04-29 19:30 ` David Lechner
0 siblings, 0 replies; only message in thread
From: David Lechner @ 2026-04-29 19:30 UTC (permalink / raw)
To: Linux PM, Felix Gu, William Breathitt Gray, Judith Mendez
Cc: linux-iio, linux-kernel
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,
^ permalink raw reply [flat|nested] only message in thread