2021-04-27 03:15:21

by Randy Dunlap

[permalink] [raw]
Subject: [PATCH] clk: <linux/clk.h>: correct clk_get_parent() documentation

Make the kernel-doc return value agree with both the stub implementation
in <linux/clk.h> and the non-stub function in drivers/clk/clk.c.

Signed-off-by: Randy Dunlap <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
---
There are several drivers that call clk_get_parent() and use its
return value as though it returns an ERR_PTR(). I am working on a
patch series to fix those.

include/linux/clk.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--- linux-next-20210426.orig/include/linux/clk.h
+++ linux-next-20210426/include/linux/clk.h
@@ -744,8 +744,8 @@ int clk_set_parent(struct clk *clk, stru
* clk_get_parent - get the parent clock source for this clock
* @clk: clock source
*
- * Returns struct clk corresponding to parent clock source, or
- * valid IS_ERR() condition containing errno.
+ * Return: &struct clk corresponding to parent clock source, or
+ * %NULL if clk is %NULL.
*/
struct clk *clk_get_parent(struct clk *clk);


2021-04-27 09:42:11

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH] clk: <linux/clk.h>: correct clk_get_parent() documentation

On Mon, Apr 26, 2021 at 08:13:42PM -0700, Randy Dunlap wrote:
> Make the kernel-doc return value agree with both the stub implementation
> in <linux/clk.h> and the non-stub function in drivers/clk/clk.c.
>
> Signed-off-by: Randy Dunlap <[email protected]>
> Cc: Russell King <[email protected]>
> Cc: [email protected]
> ---
> There are several drivers that call clk_get_parent() and use its
> return value as though it returns an ERR_PTR(). I am working on a
> patch series to fix those.

The whole premise of the CLK API is that:

- clk values that IS_ERR() returns true are errors
- clk values that IS_ERR() returns false are valid

and that is that - nice, simple, easy to understand. So the
documentation is correct. If clk_get_parent() needs to return an
error, it does so by returning an error-pointer, not by returning
NULL.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2021-04-27 17:09:35

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] clk: <linux/clk.h>: correct clk_get_parent() documentation

On 4/27/21 2:38 AM, Russell King - ARM Linux admin wrote:
> On Mon, Apr 26, 2021 at 08:13:42PM -0700, Randy Dunlap wrote:
>> Make the kernel-doc return value agree with both the stub implementation
>> in <linux/clk.h> and the non-stub function in drivers/clk/clk.c.
>>
>> Signed-off-by: Randy Dunlap <[email protected]>
>> Cc: Russell King <[email protected]>
>> Cc: [email protected]
>> ---
>> There are several drivers that call clk_get_parent() and use its
>> return value as though it returns an ERR_PTR(). I am working on a
>> patch series to fix those.
>
> The whole premise of the CLK API is that:
>
> - clk values that IS_ERR() returns true are errors
> - clk values that IS_ERR() returns false are valid
>
> and that is that - nice, simple, easy to understand. So the
> documentation is correct. If clk_get_parent() needs to return an
> error, it does so by returning an error-pointer, not by returning
> NULL.

Hm, so the 6 drivers that do this are OK then, if
clk_get_parent() returns NULL?


parent = clk_get_parent(clk);
if (IS_ERR(parent)) {
dev_err(cpu_dev, "Cannot get parent clock for CPU0\n");
clk_put(clk);
return PTR_ERR(parent);
}

/* Get parent CPU frequency */
base_frequency = clk_get_rate(parent);

boom?

--
~Randy

2021-04-27 18:05:56

by Russell King (Oracle)

[permalink] [raw]
Subject: Re: [PATCH] clk: <linux/clk.h>: correct clk_get_parent() documentation

On Tue, Apr 27, 2021 at 10:07:04AM -0700, Randy Dunlap wrote:
> On 4/27/21 2:38 AM, Russell King - ARM Linux admin wrote:
> > On Mon, Apr 26, 2021 at 08:13:42PM -0700, Randy Dunlap wrote:
> >> Make the kernel-doc return value agree with both the stub implementation
> >> in <linux/clk.h> and the non-stub function in drivers/clk/clk.c.
> >>
> >> Signed-off-by: Randy Dunlap <[email protected]>
> >> Cc: Russell King <[email protected]>
> >> Cc: [email protected]
> >> ---
> >> There are several drivers that call clk_get_parent() and use its
> >> return value as though it returns an ERR_PTR(). I am working on a
> >> patch series to fix those.
> >
> > The whole premise of the CLK API is that:
> >
> > - clk values that IS_ERR() returns true are errors
> > - clk values that IS_ERR() returns false are valid
> >
> > and that is that - nice, simple, easy to understand. So the
> > documentation is correct. If clk_get_parent() needs to return an
> > error, it does so by returning an error-pointer, not by returning
> > NULL.
>
> Hm, so the 6 drivers that do this are OK then, if
> clk_get_parent() returns NULL?
>
>
> parent = clk_get_parent(clk);
> if (IS_ERR(parent)) {
> dev_err(cpu_dev, "Cannot get parent clock for CPU0\n");
> clk_put(clk);
> return PTR_ERR(parent);
> }
>
> /* Get parent CPU frequency */
> base_frequency = clk_get_rate(parent);
>
> boom?

As I say, the premise is that only clocks where IS_ERR(clk) is true
are an error. Everything else must be treated as an acceptable clock.

Sometimes the NULL clock is used for "I don't have a clock", and that
must not cause the API to go "boom".

In the case of the CCF implementation, clk_get_rate(NULL) will return
0.

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

2021-04-27 18:13:36

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] clk: <linux/clk.h>: correct clk_get_parent() documentation

On 4/27/21 11:03 AM, Russell King - ARM Linux admin wrote:
> On Tue, Apr 27, 2021 at 10:07:04AM -0700, Randy Dunlap wrote:
>> On 4/27/21 2:38 AM, Russell King - ARM Linux admin wrote:
>>> On Mon, Apr 26, 2021 at 08:13:42PM -0700, Randy Dunlap wrote:
>>>> Make the kernel-doc return value agree with both the stub implementation
>>>> in <linux/clk.h> and the non-stub function in drivers/clk/clk.c.
>>>>
>>>> Signed-off-by: Randy Dunlap <[email protected]>
>>>> Cc: Russell King <[email protected]>
>>>> Cc: [email protected]
>>>> ---
>>>> There are several drivers that call clk_get_parent() and use its
>>>> return value as though it returns an ERR_PTR(). I am working on a
>>>> patch series to fix those.
>>>
>>> The whole premise of the CLK API is that:
>>>
>>> - clk values that IS_ERR() returns true are errors
>>> - clk values that IS_ERR() returns false are valid
>>>
>>> and that is that - nice, simple, easy to understand. So the
>>> documentation is correct. If clk_get_parent() needs to return an
>>> error, it does so by returning an error-pointer, not by returning
>>> NULL.
>>
>> Hm, so the 6 drivers that do this are OK then, if
>> clk_get_parent() returns NULL?
>>
>>
>> parent = clk_get_parent(clk);
>> if (IS_ERR(parent)) {
>> dev_err(cpu_dev, "Cannot get parent clock for CPU0\n");
>> clk_put(clk);
>> return PTR_ERR(parent);
>> }
>>
>> /* Get parent CPU frequency */
>> base_frequency = clk_get_rate(parent);
>>
>> boom?
>
> As I say, the premise is that only clocks where IS_ERR(clk) is true
> are an error. Everything else must be treated as an acceptable clock.
>
> Sometimes the NULL clock is used for "I don't have a clock", and that
> must not cause the API to go "boom".
>
> In the case of the CCF implementation, clk_get_rate(NULL) will return
> 0.
>

Thank you for the clarification. That is helpful.

--
~Randy