Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jie Gan <jie.gan@oss.qualcomm.com>
To: Leo Yan <leo.yan@arm.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>,
	Mike Leach <mike.leach@arm.com>,
	James Clark <james.clark@linaro.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Yeoreum Yun <yeoreum.yun@arm.com>,
	Yuanfang Zhang <yuanfang.zhang@oss.qualcomm.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Tingwei Zhang <tingwei.zhang@oss.qualcomm.com>,
	coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com
Subject: Re: [PATCH 1/2] coresight: Fix clock refcount imbalance on platform remove
Date: Thu, 2 Jul 2026 09:56:05 +0800	[thread overview]
Message-ID: <4e41e58e-5fbf-4564-bf9e-cec42570f3d5@oss.qualcomm.com> (raw)
In-Reply-To: <5218878b-c91f-4d14-ba12-68edf7b3f4a7@oss.qualcomm.com>


Hi Leo,

On 7/2/2026 8:59 AM, Jie Gan wrote:
> Hi Leo,
> 
> On 7/2/2026 12:23 AM, Leo Yan wrote:
>> On Wed, Jul 01, 2026 at 02:05:02PM +0800, Jie Gan wrote:
>>
>>> After probe, pm_runtime_put() allows the device to suspend and the
>>> runtime suspend callback disables the same clocks. During remove the
>>> device is left runtime suspended, so pm_runtime_disable() freezes it
>>> with the clocks already disabled. The devm cleanup that runs afterwards
>>> calls clk_disable_unprepare() a second time, underflowing the clock
>>> enable refcount.
>>
>> Thanks for fixing the issue.
>>
>> The problem is that if the device has already been runtime suspended and
>> its clock has been disabled, afterwards when remove the device, the devm
>> cleanup disables the clock again, resulting in clock count underflow.
>>
>>> diff --git a/drivers/hwtracing/coresight/coresight-funnel.c b/ 
>>> drivers/hwtracing/coresight/coresight-funnel.c
>>> index 0abc11f0690c..4c5b94640e6a 100644
>>> --- a/drivers/hwtracing/coresight/coresight-funnel.c
>>> +++ b/drivers/hwtracing/coresight/coresight-funnel.c
>>> @@ -334,6 +334,7 @@ static void funnel_platform_remove(struct 
>>> platform_device *pdev)
>>>           return;
>>>       funnel_remove(&pdev->dev);
>>> +    pm_runtime_get_sync(&pdev->dev);
>>>       pm_runtime_disable(&pdev->dev);
>>
>> Let's use the funnel driver for the discussion. Once we agree on the
>> approach, we can apply the same change to the other CoreSight platform
>> drivers.
>>
>> How about the following teardown?
>>
>>   static void funnel_platform_remove(struct platform_device *pdev)
>>   {
>>          struct funnel_drvdata *drvdata = dev_get_drvdata(&pdev->dev);
>> +       int ret;
>>
>>          if (WARN_ON(!drvdata))
>>                  return;
>>
>> +       ret = pm_runtime_get_sync(&pdev->dev);
>> +       if (ret < 0)
>> +               dev_warn(&pdev->dev, "failed to resume before remove: 
>> %d\n", ret);
>> +
>>          funnel_remove(&pdev->dev);
>> +
>>          pm_runtime_disable(&pdev->dev);
>> +       pm_runtime_set_suspended(&pdev->dev);
>> +       pm_runtime_put_noidle(&pdev->dev);
>>   }
> 
> This proposal looks good to me. I forgot to add pm_runtime_put_noidle to 
> drop the useless reference which created by pm_runtime_get_sync.
> 

I dropped the line to check the return value for simplifying.
Here is the final version from my part, can you please help to review again?

  static void funnel_platform_remove(struct platform_device *pdev)
  {
         struct funnel_drvdata *drvdata = dev_get_drvdata(&pdev->dev);

         if (WARN_ON(!drvdata))
                 return;

-       funnel_remove(&pdev->dev);
+       /*
+        * Resume the device so its clocks are enabled again, balancing the
+        * clk_disable_unprepare() that devm runs when the driver detaches.
+        * Then mark it suspended and drop the usage count taken here.
+        */
         pm_runtime_get_sync(&pdev->dev);
+       funnel_remove(&pdev->dev);
         pm_runtime_disable(&pdev->dev);
+       pm_runtime_set_suspended(&pdev->dev);
+       pm_runtime_put_noidle(&pdev->dev);
  }

Thanks,
Jie

> Thanks,
> Jie
> 
>>
>> The idea is to first resume the device with pm_runtime_get_sync(), then
>> perform the remove (which is safe if they need to access or clean up
>> hardware state), and finally clean up the runtime PM states. I mainly
>> referred to drivers/iio/adc/stm32-adc.c.
>>
>> Thanks,
>> Leo
> 



  reply	other threads:[~2026-07-02  1:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  6:05 [PATCH 0/2] fix clock refcount imbalance for all Coresight platform drivers Jie Gan
2026-07-01  6:05 ` [PATCH 1/2] coresight: Fix clock refcount imbalance on platform remove Jie Gan
2026-07-01  9:20   ` Yeoreum Yun
2026-07-01 16:23   ` Leo Yan
2026-07-02  0:59     ` Jie Gan
2026-07-02  1:56       ` Jie Gan [this message]
2026-07-02  8:28         ` Leo Yan
2026-07-01  6:05 ` [PATCH 2/2] coresight: tnoc: " Jie Gan

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=4e41e58e-5fbf-4564-bf9e-cec42570f3d5@oss.qualcomm.com \
    --to=jie.gan@oss.qualcomm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=anshuman.khandual@arm.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@linaro.org \
    --cc=leo.yan@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mike.leach@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tingwei.zhang@oss.qualcomm.com \
    --cc=yeoreum.yun@arm.com \
    --cc=yuanfang.zhang@oss.qualcomm.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