diff mbox series

[v1,4/4] PM / devfreq: tegra30: Check whether clk_round_rate() returns zero rate

Message ID 20210912184458.17995-5-digetx@gmail.com
State Accepted
Commit 4844bdbe9166bc3d194b1d20d13dc1f01d3c1bb7
Headers show
Series Make probe() of Tegra devfreq driver completely resource-managed | expand

Commit Message

Dmitry Osipenko Sept. 12, 2021, 6:44 p.m. UTC
EMC clock is always-on and can't be zero. Check whether clk_round_rate()
returns zero rate and error out if it does. It can return zero if clock
tree isn't initialized properly.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/devfreq/tegra30-devfreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Chanwoo Choi Sept. 15, 2021, 3:51 a.m. UTC | #1
Hi,

On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:
> EMC clock is always-on and can't be zero. Check whether clk_round_rate()

> returns zero rate and error out if it does. It can return zero if clock

> tree isn't initialized properly.

> 

> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

> ---

>   drivers/devfreq/tegra30-devfreq.c | 4 ++--

>   1 file changed, 2 insertions(+), 2 deletions(-)

> 

> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c

> index d83fdc2713ed..65ecf17a36f4 100644

> --- a/drivers/devfreq/tegra30-devfreq.c

> +++ b/drivers/devfreq/tegra30-devfreq.c

> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct platform_device *pdev)

>   		return err;

>   

>   	rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);

> -	if (rate < 0) {

> +	if (rate <= 0) {

>   		dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);

> -		return rate;

> +		return rate ?: -EINVAL;

>   	}

>   

>   	tegra->max_freq = rate / KHZ;

> 


Acked-by: Chanwoo Choi <cw00.choi@samsung.com>


-- 
Best Regards,
Samsung Electronics
Chanwoo Choi
Chanwoo Choi Sept. 15, 2021, 6:31 p.m. UTC | #2
On 21. 9. 15. 오후 12:51, Chanwoo Choi wrote:
> Hi,

> 

> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:

>> EMC clock is always-on and can't be zero. Check whether clk_round_rate()

>> returns zero rate and error out if it does. It can return zero if clock

>> tree isn't initialized properly.

>>

>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

>> ---

>>   drivers/devfreq/tegra30-devfreq.c | 4 ++--

>>   1 file changed, 2 insertions(+), 2 deletions(-)

>>

>> diff --git a/drivers/devfreq/tegra30-devfreq.c 

>> b/drivers/devfreq/tegra30-devfreq.c

>> index d83fdc2713ed..65ecf17a36f4 100644

>> --- a/drivers/devfreq/tegra30-devfreq.c

>> +++ b/drivers/devfreq/tegra30-devfreq.c

>> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct 

>> platform_device *pdev)

>>           return err;

>>       rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);

>> -    if (rate < 0) {

>> +    if (rate <= 0) {

>>           dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);

>> -        return rate;

>> +        return rate ?: -EINVAL;


If rate is 0, It doesn't return and fall-through? even if print the 
error message. 'return rate ?: -EINVAL;' style is strange for me
because it doesn't specify the 'return value' when rate is true.


-- 
Best Regards,
Samsung Electronics
Chanwoo Choi
Dmitry Osipenko Sept. 16, 2021, 1:28 a.m. UTC | #3
15.09.2021 21:31, Chanwoo Choi пишет:
> On 21. 9. 15. 오후 12:51, Chanwoo Choi wrote:

>> Hi,

>>

>> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:

>>> EMC clock is always-on and can't be zero. Check whether clk_round_rate()

>>> returns zero rate and error out if it does. It can return zero if clock

>>> tree isn't initialized properly.

>>>

>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

>>> ---

>>>   drivers/devfreq/tegra30-devfreq.c | 4 ++--

>>>   1 file changed, 2 insertions(+), 2 deletions(-)

>>>

>>> diff --git a/drivers/devfreq/tegra30-devfreq.c

>>> b/drivers/devfreq/tegra30-devfreq.c

>>> index d83fdc2713ed..65ecf17a36f4 100644

>>> --- a/drivers/devfreq/tegra30-devfreq.c

>>> +++ b/drivers/devfreq/tegra30-devfreq.c

>>> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct

>>> platform_device *pdev)

>>>           return err;

>>>       rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);

>>> -    if (rate < 0) {

>>> +    if (rate <= 0) {

>>>           dev_err(&pdev->dev, "Failed to round clock rate: %ld\n",

>>> rate);

>>> -        return rate;

>>> +        return rate ?: -EINVAL;

> 

> If rate is 0, It doesn't return and fall-through? even if print the

> error message. 'return rate ?: -EINVAL;' style is strange for me

> because it doesn't specify the 'return value' when rate is true.


It's not clear to me what do you mean by "return and fall-through".

It specifies the 'return value' when rate is true. It's a short form of
"rate ? rate : -EINVAL".

The final returned value will be printed by the driver's core. The value
returned by clk_round_rate() is important here since it tells the reason
of the error.

https://elixir.bootlin.com/linux/v5.15-rc1/source/drivers/base/dd.c#L533
Chanwoo Choi Sept. 19, 2021, 9:43 a.m. UTC | #4
On 21. 9. 16. 오전 10:28, Dmitry Osipenko wrote:
> 15.09.2021 21:31, Chanwoo Choi пишет:

>> On 21. 9. 15. 오후 12:51, Chanwoo Choi wrote:

>>> Hi,

>>>

>>> On 21. 9. 13. 오전 3:44, Dmitry Osipenko wrote:

>>>> EMC clock is always-on and can't be zero. Check whether clk_round_rate()

>>>> returns zero rate and error out if it does. It can return zero if clock

>>>> tree isn't initialized properly.

>>>>

>>>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

>>>> ---

>>>>    drivers/devfreq/tegra30-devfreq.c | 4 ++--

>>>>    1 file changed, 2 insertions(+), 2 deletions(-)

>>>>

>>>> diff --git a/drivers/devfreq/tegra30-devfreq.c

>>>> b/drivers/devfreq/tegra30-devfreq.c

>>>> index d83fdc2713ed..65ecf17a36f4 100644

>>>> --- a/drivers/devfreq/tegra30-devfreq.c

>>>> +++ b/drivers/devfreq/tegra30-devfreq.c

>>>> @@ -891,9 +891,9 @@ static int tegra_devfreq_probe(struct

>>>> platform_device *pdev)

>>>>            return err;

>>>>        rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);

>>>> -    if (rate < 0) {

>>>> +    if (rate <= 0) {

>>>>            dev_err(&pdev->dev, "Failed to round clock rate: %ld\n",

>>>> rate);

>>>> -        return rate;

>>>> +        return rate ?: -EINVAL;

>>

>> If rate is 0, It doesn't return and fall-through? even if print the

>> error message. 'return rate ?: -EINVAL;' style is strange for me

>> because it doesn't specify the 'return value' when rate is true.

> 

> It's not clear to me what do you mean by "return and fall-through".

> 

> It specifies the 'return value' when rate is true. It's a short form of

> "rate ? rate : -EINVAL".


I has not known this short form. Thanks for comment. I understand.



-- 
Best Regards,
Samsung Electronics
Chanwoo Choi
diff mbox series

Patch

diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index d83fdc2713ed..65ecf17a36f4 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -891,9 +891,9 @@  static int tegra_devfreq_probe(struct platform_device *pdev)
 		return err;
 
 	rate = clk_round_rate(tegra->emc_clock, ULONG_MAX);
-	if (rate < 0) {
+	if (rate <= 0) {
 		dev_err(&pdev->dev, "Failed to round clock rate: %ld\n", rate);
-		return rate;
+		return rate ?: -EINVAL;
 	}
 
 	tegra->max_freq = rate / KHZ;