diff mbox series

[v2] clk: fix clk_get_rate() documentation

Message ID 20210214021718.2235342-1-giulio.benetti@benettiengineering.com
State Accepted
Commit 9e578f6340ba3f4324cd823872afe6eda39857d2
Delegated to: Lukasz Majewski
Headers show
Series [v2] clk: fix clk_get_rate() documentation | expand

Commit Message

Giulio Benetti Feb. 14, 2021, 2:17 a.m. UTC
Improve clk_get_rate() @return documentation that otherwise is a bit
ambiguous. At the moment I expect to return 0 as error since the return
type is 'ulong', instead the function really returns negative value in
case the corresponding function pointer is null and returns 0 if the clock
is invalid.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
---
V1->V2:
* previous comment was wrong, this function returns negative value, so let's
  improve it's @return documentation as suggested by Simon Glass
---
 include/clk.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jesse T Feb. 14, 2021, 2:58 a.m. UTC | #1
This looks good to me, and helps beginners like me. As for the function
itself, i have 2 concerns: If it does return a negative value why is it
unsigned, if it is in fact signed that a clock above 2.2Ghz is a negative
number. As for the IS_ERR_VALUE macro there still is a chance that it will
error if the clock just so happens to be 2^31  through 2^31 + number of err
values. Just voicing my concerns i assume as i learn more about uboot,
linux,rtos's and different programs there will be minor issues like this.

On Sat, Feb 13, 2021 at 9:17 PM Giulio Benetti <
giulio.benetti@benettiengineering.com> wrote:

> Improve clk_get_rate() @return documentation that otherwise is a bit
> ambiguous. At the moment I expect to return 0 as error since the return
> type is 'ulong', instead the function really returns negative value in
> case the corresponding function pointer is null and returns 0 if the clock
> is invalid.
>
> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
> ---
> V1->V2:
> * previous comment was wrong, this function returns negative value, so
> let's
>   improve it's @return documentation as suggested by Simon Glass
> ---
>  include/clk.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/clk.h b/include/clk.h
> index ca6b85fa6f..5a8c7244d0 100644
> --- a/include/clk.h
> +++ b/include/clk.h
> @@ -344,7 +344,8 @@ int clk_free(struct clk *clk);
>   *
>   * @clk:       A clock struct that was previously successfully requested
> by
>   *             clk_request/get_by_*().
> - * @return clock rate in Hz, or -ve error code.
> + * @return clock rate in Hz on success, 0 for invalid clock, or -ve error
> code
> + *        for other errors.
>   */
>  ulong clk_get_rate(struct clk *clk);
>
> --
> 2.25.1
>
>
Giulio Benetti Feb. 14, 2021, 3:17 a.m. UTC | #2
Hi Jesse,

> Il giorno 14 feb 2021, alle ore 03:58, Jesse T <mr.bossman075@gmail.com> ha scritto:
> 
> 
> This looks good to me, and helps beginners like me. As for the function itself, i have 2 concerns: If it does return a negative value why is it unsigned, if it is in fact signed that a clock above 2.2Ghz is a negative number.

I was worried too at first sight but if you try to check negative numbers you see that -1 is 0xFFFFFFFF so in the worst case you only loose 4095 numbers from the maximum, try to check with hex calculator. And that is the trick.

> As for the IS_ERR_VALUE macro there still is a chance that it will error if the clock just so happens to be 2^31  through 2^31 + number of err values.

This is answered from above and IS_ERR_VALUE is a very contracted macro that basically let you to keep value NOT valid if (0 > value > 4095). 

> Just voicing my concerns i assume as i learn more about uboot, linux,rtos's and different programs there will be minor issues like this. 

Sure, no problem :-)

Giulio

> 
>> On Sat, Feb 13, 2021 at 9:17 PM Giulio Benetti <giulio.benetti@benettiengineering.com> wrote:
>> Improve clk_get_rate() @return documentation that otherwise is a bit
>> ambiguous. At the moment I expect to return 0 as error since the return
>> type is 'ulong', instead the function really returns negative value in
>> case the corresponding function pointer is null and returns 0 if the clock
>> is invalid.
>> 
>> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
>> ---
>> V1->V2:
>> * previous comment was wrong, this function returns negative value, so let's
>>   improve it's @return documentation as suggested by Simon Glass
>> ---
>>  include/clk.h | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/include/clk.h b/include/clk.h
>> index ca6b85fa6f..5a8c7244d0 100644
>> --- a/include/clk.h
>> +++ b/include/clk.h
>> @@ -344,7 +344,8 @@ int clk_free(struct clk *clk);
>>   *
>>   * @clk:       A clock struct that was previously successfully requested by
>>   *             clk_request/get_by_*().
>> - * @return clock rate in Hz, or -ve error code.
>> + * @return clock rate in Hz on success, 0 for invalid clock, or -ve error code
>> + *        for other errors.
>>   */
>>  ulong clk_get_rate(struct clk *clk);
>> 
>> -- 
>> 2.25.1
>>
Jesse T Feb. 14, 2021, 3:49 a.m. UTC | #3
Awesome, thanks! I must have forgotten how twos complement works for a
sec...

On Sat, Feb 13, 2021 at 10:17 PM Giulio Benetti <
giulio.benetti@benettiengineering.com> wrote:

> Hi Jesse,
>
> Il giorno 14 feb 2021, alle ore 03:58, Jesse T <mr.bossman075@gmail.com>
> ha scritto:
>
> 
> This looks good to me, and helps beginners like me. As for the function
> itself, i have 2 concerns: If it does return a negative value why is it
> unsigned, if it is in fact signed that a clock above 2.2Ghz is a negative
> number.
>
>
> I was worried too at first sight but if you try to check negative numbers
> you see that -1 is 0xFFFFFFFF so in the worst case you only loose 4095
> numbers from the maximum, try to check with hex calculator. And that is the
> trick.
>
> As for the IS_ERR_VALUE macro there still is a chance that it will error
> if the clock just so happens to be 2^31  through 2^31 + number of err
> values.
>
>
> This is answered from above and IS_ERR_VALUE is a very contracted macro
> that basically let you to keep value NOT valid if (0 > value > 4095).
>
> Just voicing my concerns i assume as i learn more about uboot,
> linux,rtos's and different programs there will be minor issues like this.
>
>
> Sure, no problem :-)
>
> Giulio
>
>
> On Sat, Feb 13, 2021 at 9:17 PM Giulio Benetti <
> giulio.benetti@benettiengineering.com> wrote:
>
>> Improve clk_get_rate() @return documentation that otherwise is a bit
>> ambiguous. At the moment I expect to return 0 as error since the return
>> type is 'ulong', instead the function really returns negative value in
>> case the corresponding function pointer is null and returns 0 if the clock
>> is invalid.
>>
>> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
>> ---
>> V1->V2:
>> * previous comment was wrong, this function returns negative value, so
>> let's
>>   improve it's @return documentation as suggested by Simon Glass
>> ---
>>  include/clk.h | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/clk.h b/include/clk.h
>> index ca6b85fa6f..5a8c7244d0 100644
>> --- a/include/clk.h
>> +++ b/include/clk.h
>> @@ -344,7 +344,8 @@ int clk_free(struct clk *clk);
>>   *
>>   * @clk:       A clock struct that was previously successfully requested
>> by
>>   *             clk_request/get_by_*().
>> - * @return clock rate in Hz, or -ve error code.
>> + * @return clock rate in Hz on success, 0 for invalid clock, or -ve
>> error code
>> + *        for other errors.
>>   */
>>  ulong clk_get_rate(struct clk *clk);
>>
>> --
>> 2.25.1
>>
>>
Heinrich Schuchardt Feb. 22, 2021, 7:13 p.m. UTC | #4
On 2/14/21 4:49 AM, Jesse T wrote:
> Awesome, thanks! I must have forgotten how twos complement works for a
> sec...
>
> On Sat, Feb 13, 2021 at 10:17 PM Giulio Benetti <
> giulio.benetti@benettiengineering.com> wrote:
>
>> Hi Jesse,
>>
>> Il giorno 14 feb 2021, alle ore 03:58, Jesse T <mr.bossman075@gmail.com>
>> ha scritto:
>>
>> 
>> This looks good to me, and helps beginners like me. As for the function
>> itself, i have 2 concerns: If it does return a negative value why is it
>> unsigned, if it is in fact signed that a clock above 2.2Ghz is a negative
>> number.
>>
>>
>> I was worried too at first sight but if you try to check negative numbers
>> you see that -1 is 0xFFFFFFFF so in the worst case you only loose 4095
>> numbers from the maximum, try to check with hex calculator. And that is the
>> trick.
>>
>> As for the IS_ERR_VALUE macro there still is a chance that it will error
>> if the clock just so happens to be 2^31  through 2^31 + number of err
>> values.
>>
>>
>> This is answered from above and IS_ERR_VALUE is a very contracted macro
>> that basically let you to keep value NOT valid if (0 > value > 4095).
>>
>> Just voicing my concerns i assume as i learn more about uboot,
>> linux,rtos's and different programs there will be minor issues like this.
>>
>>
>> Sure, no problem :-)
>>
>> Giulio
>>
>>
>> On Sat, Feb 13, 2021 at 9:17 PM Giulio Benetti <
>> giulio.benetti@benettiengineering.com> wrote:
>>
>>> Improve clk_get_rate() @return documentation that otherwise is a bit
>>> ambiguous. At the moment I expect to return 0 as error since the return
>>> type is 'ulong', instead the function really returns negative value in
>>> case the corresponding function pointer is null and returns 0 if the clock
>>> is invalid.
>>>
>>> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
>>> ---
>>> V1->V2:
>>> * previous comment was wrong, this function returns negative value, so
>>> let's
>>>    improve it's @return documentation as suggested by Simon Glass
>>> ---
>>>   include/clk.h | 3 ++-
>>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/clk.h b/include/clk.h
>>> index ca6b85fa6f..5a8c7244d0 100644
>>> --- a/include/clk.h
>>> +++ b/include/clk.h
>>> @@ -344,7 +344,8 @@ int clk_free(struct clk *clk);
>>>    *
>>>    * @clk:       A clock struct that was previously successfully requested
>>> by
>>>    *             clk_request/get_by_*().
>>> - * @return clock rate in Hz, or -ve error code.
>>> + * @return clock rate in Hz on success, 0 for invalid clock, or -ve
>>> error code
>>> + *        for other errors.
>>>    */
>>>   ulong clk_get_rate(struct clk *clk);
>>>
>>> --
>>> 2.25.1
>>>
>>>

Cc: Lukasz Majewski <lukma@denx.de>
Lukasz is maintainer for CLOCK.
Giulio Benetti Feb. 23, 2021, 12:25 a.m. UTC | #5
On 2/22/21 8:13 PM, Heinrich Schuchardt wrote:
> On 2/14/21 4:49 AM, Jesse T wrote:
>> Awesome, thanks! I must have forgotten how twos complement works for a
>> sec...
>>
>> On Sat, Feb 13, 2021 at 10:17 PM Giulio Benetti <
>> giulio.benetti@benettiengineering.com> wrote:
>>
>>> Hi Jesse,
>>>
>>> Il giorno 14 feb 2021, alle ore 03:58, Jesse T <mr.bossman075@gmail.com>
>>> ha scritto:
>>>
>>> 
>>> This looks good to me, and helps beginners like me. As for the function
>>> itself, i have 2 concerns: If it does return a negative value why is it
>>> unsigned, if it is in fact signed that a clock above 2.2Ghz is a negative
>>> number.
>>>
>>>
>>> I was worried too at first sight but if you try to check negative numbers
>>> you see that -1 is 0xFFFFFFFF so in the worst case you only loose 4095
>>> numbers from the maximum, try to check with hex calculator. And that is the
>>> trick.
>>>
>>> As for the IS_ERR_VALUE macro there still is a chance that it will error
>>> if the clock just so happens to be 2^31  through 2^31 + number of err
>>> values.
>>>
>>>
>>> This is answered from above and IS_ERR_VALUE is a very contracted macro
>>> that basically let you to keep value NOT valid if (0 > value > 4095).
>>>
>>> Just voicing my concerns i assume as i learn more about uboot,
>>> linux,rtos's and different programs there will be minor issues like this.
>>>
>>>
>>> Sure, no problem :-)
>>>
>>> Giulio
>>>
>>>
>>> On Sat, Feb 13, 2021 at 9:17 PM Giulio Benetti <
>>> giulio.benetti@benettiengineering.com> wrote:
>>>
>>>> Improve clk_get_rate() @return documentation that otherwise is a bit
>>>> ambiguous. At the moment I expect to return 0 as error since the return
>>>> type is 'ulong', instead the function really returns negative value in
>>>> case the corresponding function pointer is null and returns 0 if the clock
>>>> is invalid.
>>>>
>>>> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
>>>> ---
>>>> V1->V2:
>>>> * previous comment was wrong, this function returns negative value, so
>>>> let's
>>>>     improve it's @return documentation as suggested by Simon Glass
>>>> ---
>>>>    include/clk.h | 3 ++-
>>>>    1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/include/clk.h b/include/clk.h
>>>> index ca6b85fa6f..5a8c7244d0 100644
>>>> --- a/include/clk.h
>>>> +++ b/include/clk.h
>>>> @@ -344,7 +344,8 @@ int clk_free(struct clk *clk);
>>>>     *
>>>>     * @clk:       A clock struct that was previously successfully requested
>>>> by
>>>>     *             clk_request/get_by_*().
>>>> - * @return clock rate in Hz, or -ve error code.
>>>> + * @return clock rate in Hz on success, 0 for invalid clock, or -ve
>>>> error code
>>>> + *        for other errors.
>>>>     */
>>>>    ulong clk_get_rate(struct clk *clk);
>>>>
>>>> --
>>>> 2.25.1
>>>>
>>>>
> 
> Cc: Lukasz Majewski <lukma@denx.de>
> Lukasz is maintainer for CLOCK.

Ah thank you that's right. I've missed it because 
./scripts/get_maintainer.pl didn't list him.
Giulio Benetti April 4, 2021, 6:56 p.m. UTC | #6
Hi Lukasz,

kindly ping

Best regards
Sean Anderson Nov. 24, 2021, 4:01 a.m. UTC | #7
On 2/13/21 9:17 PM, Giulio Benetti wrote:
> Improve clk_get_rate() @return documentation that otherwise is a bit
> ambiguous. At the moment I expect to return 0 as error since the return
> type is 'ulong', instead the function really returns negative value in
> case the corresponding function pointer is null and returns 0 if the clock
> is invalid.
> 
> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
> ---
> V1->V2:
> * previous comment was wrong, this function returns negative value, so let's
>    improve it's @return documentation as suggested by Simon Glass
> ---
>   include/clk.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/clk.h b/include/clk.h
> index ca6b85fa6f..5a8c7244d0 100644
> --- a/include/clk.h
> +++ b/include/clk.h
> @@ -344,7 +344,8 @@ int clk_free(struct clk *clk);
>    *
>    * @clk:	A clock struct that was previously successfully requested by
>    *		clk_request/get_by_*().
> - * @return clock rate in Hz, or -ve error code.
> + * @return clock rate in Hz on success, 0 for invalid clock, or -ve error code
> + *	   for other errors.
>    */
>   ulong clk_get_rate(struct clk *clk);
>   
> 

Reviewed-by: Sean Anderson <seanga2@gmail.com>
Sean Anderson Dec. 15, 2021, 7:05 p.m. UTC | #8
On Sun, 14 Feb 2021 03:17:18 +0100, Giulio Benetti wrote:
> Improve clk_get_rate() @return documentation that otherwise is a bit
> ambiguous. At the moment I expect to return 0 as error since the return
> type is 'ulong', instead the function really returns negative value in
> case the corresponding function pointer is null and returns 0 if the clock
> is invalid.
> 
> 
> [...]

Applied, thanks!

[1/1] clk: fix clk_get_rate() documentation
      commit: 9e578f6340ba3f4324cd823872afe6eda39857d2

Best regards,
diff mbox series

Patch

diff --git a/include/clk.h b/include/clk.h
index ca6b85fa6f..5a8c7244d0 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -344,7 +344,8 @@  int clk_free(struct clk *clk);
  *
  * @clk:	A clock struct that was previously successfully requested by
  *		clk_request/get_by_*().
- * @return clock rate in Hz, or -ve error code.
+ * @return clock rate in Hz on success, 0 for invalid clock, or -ve error code
+ *	   for other errors.
  */
 ulong clk_get_rate(struct clk *clk);