Re: [PATCH 1/1] clk: Document of_clk_get_by_name() return values

From: Dan Carpenter

Date: Tue Sep 15 2026 - 14:07:19 EST


On Tue, Sep 15, 2026 at 07:38:23PM +0300, Dan Carpenter wrote:
> Callers should test the return from of_clk_get_by_name() with IS_ERR().
> The function returns a valid clock on success and an error pointer on
> failure; NULL is not a valid return value.
>
> Document this explicitly to prevent callers from treating NULL as a
> separate failure case.
>
> Assisted-by: ChatGPT:gpt-5
> Signed-off-by: Dan Carpenter <error27@xxxxxxxxx>
> ---
> There are a few other functions which look like they return NULL but
> never actually do. This is one which has caused some confusion in
> the past.

Sashiko says that it looks like it can return NULL.
https://lore.kernel.org/all/20260915164913.597D51F000FF@xxxxxxxxxxxxxxx/
It does *look* that way, which is why I'm adding the documentation
to say that looks are confusing.

It's pretty normal for these types of functions to return an error pointer
for errors and NULL for not found, but the of_clk_get_by_name() returns
-ENOENT on error. https://lkml.iu.edu/1810.1/06936.html

Also in commit 6a636d203cc8 ("clk: renesas: Use IS_ERR() for pointers
that cannot be NULL") there was a static checker warning because the
NULL return wasn't handled and we "fixed" it by saying that NULL was
impossible.

regards,
dan carpenter