All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Masney <bmasney@redhat.com>
To: Praveen Talari <praveen.talari@oss.qualcomm.com>
Cc: bjorn.andersson@oss.qualcomm.com,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	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
Subject: Re: [PATCH] clk: Guard clk_round_rate() against error pointers
Date: Thu, 23 Jul 2026 10:29:52 -0400	[thread overview]
Message-ID: <amIlYNjWeJQ9tcOB@redhat.com> (raw)
In-Reply-To: <20260723-fix_ptr_check_on_clk-v1-1-568a7ed87746@oss.qualcomm.com>

Hi Praveen,

On Thu, Jul 23, 2026 at 11:40:47AM +0530, Praveen Talari wrote:
> clk_round_rate() only checks for a NULL clk pointer before
> dereferencing it, but callers such as dev_pm_opp_set_rate() can pass
> it an error pointer (e.g. ERR_PTR(-ENOENT) left behind by
> clk_get() when a device has no Linux clock and is instead managed by
> firmware via a genpd/OPP performance domain).
> 
> Dereferencing that error pointer to read clk->exclusive_count
> crashes with an unhandled kernel NULL pointer dereference, since
> ERR_PTR(-ENOENT) plus the field's offset lands on a small, unmapped
> address:
> 
>   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
> 
> Change the guard from "if (!clk)" to "if (IS_ERR_OR_NULL(clk))",
> matching the pattern already used by other clk consumer API
> functions such as clk_unprepare(), so an error pointer is rejected
> the same way a NULL pointer is.
> 
> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com>
> ---
>  drivers/clk/clk.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 048adfa86a5d..8c1ad3d10284 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -1780,7 +1780,7 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
>  	struct clk_rate_request req;
>  	int ret;
>  
> -	if (!clk)
> +	if (IS_ERR_OR_NULL(clk))

Can you provide more details about the clk_get() call point that starts this
error? Specifically which driver this occurs in and the exact scenario that
triggers this.

Brian


  reply	other threads:[~2026-07-23 14:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  6:10 [PATCH] clk: Guard clk_round_rate() against error pointers Praveen Talari
2026-07-23 14:29 ` Brian Masney [this message]
2026-07-23 16:40   ` Praveen Talari

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=amIlYNjWeJQ9tcOB@redhat.com \
    --to=bmasney@redhat.com \
    --cc=bjorn.andersson@oss.qualcomm.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=mturquette@baylibre.com \
    --cc=mukesh.savaliya@oss.qualcomm.com \
    --cc=praveen.talari@oss.qualcomm.com \
    --cc=sboyd@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.