Re: [PATCH] arch_topology: Fix incorrect error check in topology_parse_cpu_capacity()

From: Dan Carpenter

Date: Tue Sep 23 2025 - 06:24:47 EST


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.

regards,
dan carpenter