public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rajendra Nayak <rnayak@codeaurora.org>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: sboyd@kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC] opp: Fixup release of clock when using set/put clkname
Date: Tue, 14 Apr 2020 20:35:26 +0530	[thread overview]
Message-ID: <83c523d0-e18e-0401-5456-2dbba524ee98@codeaurora.org> (raw)
In-Reply-To: <20200414071823.jdhkprtkizyeua23@vireshk-i7>


On 4/14/2020 12:48 PM, Viresh Kumar wrote:
> On 14-04-20, 12:45, Rajendra Nayak wrote:
>> Fixup dev_pm_opp_put_clkname() to check for a valid clock pointer
>> before it does a clk_put, since its likely that
>> _opp_table_kref_release() has already done a clk_put. Also fixup
> 
> kref release is the last thing that happens on the table, it can't get
> called after dev_pm_opp_put_clkname().

so in cases where I do have an OPP table for a device in DT and I do
dev_pm_opp_set_clkname()
dev_pm_opp_of_add_table()

and clean it up with a
dev_pm_opp_of_remove_table()
dev_pm_opp_put_clkname()

things seem to work fine as expected.

However, given I call these unconditionally in common drivers and on
some (old) platforms we really don't have an OPP table (only scale clocks)
things get a little tricky. So looks like the ref counting in such cases
gets messed up, and we end up with dev_pm_opp_of_remove_table() calling
_opp_table_kref_release() and releasing the clock, and then the subsequent
call to dev_pm_opp_put_clkname() crashes.

>> _opp_table_kref_release() to set the clock pointer to ERR_PTR(-EINVAL)
>> after its done doing a clk_put so dev_pm_opp_put_clkname() can then
>> catch it.
>>
>> Signed-off-by: Rajendra Nayak <rnayak@codeaurora.org>
>> ---
>>   drivers/opp/core.c | 10 +++++++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
>> index e4f01e7..6d064a8 100644
>> --- a/drivers/opp/core.c
>> +++ b/drivers/opp/core.c
>> @@ -1061,8 +1061,10 @@ static void _opp_table_kref_release(struct kref *kref)
>>   	_of_clear_opp_table(opp_table);
>>   
>>   	/* Release clk */
>> -	if (!IS_ERR(opp_table->clk))
>> +	if (!IS_ERR(opp_table->clk)) {
>>   		clk_put(opp_table->clk);
>> +		opp_table->clk = ERR_PTR(-EINVAL);
>> +	}
>>   
>>   	WARN_ON(!list_empty(&opp_table->opp_list));
>>   
>> @@ -1744,8 +1746,10 @@ void dev_pm_opp_put_clkname(struct opp_table *opp_table)
>>   	/* Make sure there are no concurrent readers while updating opp_table */
>>   	WARN_ON(!list_empty(&opp_table->opp_list));
>>   
>> -	clk_put(opp_table->clk);
>> -	opp_table->clk = ERR_PTR(-EINVAL);
>> +	if (!IS_ERR(opp_table->clk)) {
>> +		clk_put(opp_table->clk);
>> +		opp_table->clk = ERR_PTR(-EINVAL);
>> +	}
>>   
>>   	dev_pm_opp_put_opp_table(opp_table);
>>   }
>> -- 
>> QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
>> of Code Aurora Forum, hosted by The Linux Foundation
> 

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation

  reply	other threads:[~2020-04-14 15:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14  7:15 [RFC] opp: Fixup release of clock when using set/put clkname Rajendra Nayak
2020-04-14  7:18 ` Viresh Kumar
2020-04-14 15:05   ` Rajendra Nayak [this message]
2020-04-15  5:13     ` Viresh Kumar

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=83c523d0-e18e-0401-5456-2dbba524ee98@codeaurora.org \
    --to=rnayak@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=viresh.kumar@linaro.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