The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Kaushlendra Kumar <kaushlendra.kumar@intel.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	gregkh@linuxfoundation.org, dakr@kernel.org, rafael@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arch_topology: Fix incorrect error check in topology_parse_cpu_capacity()
Date: Tue, 23 Sep 2025 11:27:45 +0100	[thread overview]
Message-ID: <aNJ2IX2vuF8ZOmGj@bogus> (raw)
In-Reply-To: <aNJ1aY0AuATEKjDN@stanley.mountain>

On Tue, Sep 23, 2025 at 01:24:41PM +0300, Dan Carpenter wrote:
> On Tue, Sep 23, 2025 at 09:40:28AM +0100, Sudeep Holla wrote:
> > On Tue, Sep 23, 2025 at 12:55:20PM +0530, Kaushlendra Kumar wrote:
> > > Fix incorrect use of PTR_ERR_OR_ZERO() in topology_parse_cpu_capacity()
> > > which causes the code to proceed with NULL clock pointers. The current
> > > logic uses !PTR_ERR_OR_ZERO(cpu_clk) which evaluates to true for both
> > > valid pointers and NULL, leading to potential NULL pointer dereference
> > > in clk_get_rate().
> > > 
> > > PTR_ERR_OR_ZERO(cpu_clk) returns:
> > > - 0 if cpu_clk is a valid pointer or NULL
> > > - error code if cpu_clk is an error pointer
> > > 
> > > Therefore !PTR_ERR_OR_ZERO(cpu_clk) is true for both valid pointers and
> > > NULL, causing the code to call clk_get_rate(NULL) when of_clk_get()
> > > returns NULL. Replace with IS_ERR_OR_NULL() which correctly identifies
> > > only valid pointers, ensuring clk_get_rate() is called only with valid
> > > clock objects.
> > >
> > 
> > Nice catch, wonder how it survived so long unnoticed.
> 
> I don't think of_clk_get() can actually return NULL...  It's still worth
> fixing but I don't think it affects real life.
> 

Ah that explains, just looked at PTR_ERR_OR_ZERO and wondered. Thanks
for the details.

-- 
Regards,
Sudeep

      reply	other threads:[~2025-09-23 10:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23  7:25 [PATCH] arch_topology: Fix incorrect error check in topology_parse_cpu_capacity() Kaushlendra Kumar
2025-09-23  7:46 ` Markus Elfring
2025-09-23  8:50   ` Kumar, Kaushlendra
2025-09-23  8:40 ` Sudeep Holla
2025-09-23 10:24   ` Dan Carpenter
2025-09-23 10:27     ` Sudeep Holla [this message]

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=aNJ2IX2vuF8ZOmGj@bogus \
    --to=sudeep.holla@arm.com \
    --cc=dakr@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kaushlendra.kumar@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@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