From: Praveen Talari <praveen.talari@oss.qualcomm.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: bjorn.andersson@oss.qualcomm.com,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney@redhat.com>,
konrad.dybcio@oss.qualcomm.com, mukesh.savaliya@oss.qualcomm.com,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
chandana.chiluveru@oss.qualcomm.com,
Sebastian Reichel <sre@kernel.org>,
Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
linux-pm@vger.kernel.org
Subject: Re: [PATCH v3] opp: Use clk_get_optional() to avoid leaving opp_table->clk as an error pointer
Date: Mon, 27 Jul 2026 15:11:35 +0530 [thread overview]
Message-ID: <f4a3c2a7-0732-4d4c-b252-2ac5ea3db35a@oss.qualcomm.com> (raw)
In-Reply-To: <sl7wx7n2bocrfcsqj72vp3snchbgvtkuahq4pjzpor54bg46ek@ar62czwob4j5>
Hi viresh
On 27-07-2026 10:44, Viresh Kumar wrote:
> On 27-07-26, 09:46, Praveen Talari wrote:
>> _update_opp_table_clk() uses clk_get(dev, NULL) to acquire the
>> device's clock. On platforms where the perf domain device has no
>> Linux clock and is instead managed entirely by firmware via
>> devm_pm_opp_of_add_table() (through
>> of_genpd_add_provider_simple()/onecell()), clk_get() returns
>> -ENOENT. That case is treated as valid (the OPP table can still
>> have entries sourced from firmware), but opp_table->clk is left
>> holding ERR_PTR(-ENOENT) rather than being reset to NULL:
>>
>> opp_table->clk = clk_get(dev, NULL);
>> ret = PTR_ERR_OR_ZERO(opp_table->clk);
>> ...
>> if (ret == -ENOENT) {
>> opp_table->clk_count = 1;
>> return opp_table; /* opp_table->clk is still ERR_PTR(-ENOENT) */
>> }
>>
>> Consumers that only check IS_ERR(opp_table->clk) treat this as a
>> valid clk and pass it straight into the clk consumer API. In
>> particular, dev_pm_opp_set_rate() calls
>> clk_round_rate(opp_table->clk, target_freq), and clk_round_rate()
>> only guards against a NULL clk, so it dereferences the error pointer
>> to read clk->exclusive_count and crashes:
>>
>> Unable to handle kernel NULL pointer dereference at virtual
>> address 000000000000002e
>> ...
>> pc : clk_round_rate+0x3c/0x188
>> ...
>> Call trace:
>> clk_round_rate+0x3c/0x188 (P)
>> dev_pm_opp_set_rate+0x114/0x33c
>>
>> Rather than teaching every clk consumer API to special-case
>> ERR_PTR(-ENOENT), fix it at the source: use clk_get_optional()
>> instead of clk_get() in _update_opp_table_clk(), which already
>> translates -ENOENT into a NULL clk. This documents that the clock is
>> genuinely optional for such devices, and keeps opp_table->clk holding
>> either a valid clk or NULL, never a lingering -ENOENT error pointer.
>> _opp_config_clk_single() is only wired up via opp_table->config_clks
>> when a clk was actually found, and every other opp_table->clk
>> consumer already tolerates NULL through the standard clk API (which
>> treats a NULL clk as a no-op), so no other call site needs to change.
>>
>> Suggested-by: Sebastian Reichel <sre@kernel.org>
>> Reviewed-by: Sebastian Reichel <sre@kernel.org>
>> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
>> ---
> I am getting this with git am -3, please rebase over [1].
I have followed below steps but faced conflict while rebasing it.
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git remote add viresh
https://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git
git fetch viresh
git rebase viresh/cpufreq/arm/linux-next
$git rebase viresh/cpufreq/arm/linux-next
Auto-merging drivers/gpio/gpio-shared-proxy.c
CONFLICT (content): Merge conflict in drivers/gpio/gpio-shared-proxy.c
error: could not apply efecde8a254d... gpio: shared-proxy: always
serialize with a sleeping mutex
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git
rebase --abort".
Could not apply efecde8a254d... gpio: shared-proxy: always serialize
with a sleeping mutex
How to proceed further?
>
> Applying: opp: Use clk_get_optional() to avoid leaving opp_table->clk as an error pointer
> error: unrecognized input
> error: could not build fake ancestor
>
>> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
>> + opp_table->clk = clk_get_optional(dev, NULL);
>>
>> ret = PTR_ERR_OR_ZERO(opp_table->clk);
>> - if (!ret) {
>> - opp_table->config_clks = _opp_config_clk_single;
>> - opp_table->clk_count = 1;
>> - return opp_table;
>> + if (ret) {
> Since `ret` isn't used later anymore, you can instead do this and drop
> `ret` ?
> if (IS_ERR(opp_table->clk))
Sure, will fix in next patch.
Thanks,
Praveen Talari
>
>> + dev_pm_opp_put_opp_table(opp_table);
>> + dev_err_probe(dev, ret, "Couldn't find clock\n");
>> + return ERR_PTR(ret);
>> }
next prev parent reply other threads:[~2026-07-27 9:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 4:16 Praveen Talari
2026-07-27 5:14 ` Viresh Kumar
2026-07-27 9:41 ` Praveen Talari [this message]
2026-07-27 10:15 ` 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=f4a3c2a7-0732-4d4c-b252-2ac5ea3db35a@oss.qualcomm.com \
--to=praveen.talari@oss.qualcomm.com \
--cc=bjorn.andersson@oss.qualcomm.com \
--cc=bmasney@redhat.com \
--cc=chandana.chiluveru@oss.qualcomm.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=mukesh.savaliya@oss.qualcomm.com \
--cc=nm@ti.com \
--cc=sboyd@kernel.org \
--cc=sre@kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=vireshk@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
all inboxes | Powered by JetHome®