Skip to contentSkip to conversation

clk: fix clk_get_rate() always return ulong

RFC PATCH Superseded Julien Masson 3 participants 4 messages Aug 26, 2022 – Aug 29, 2022 Common clk

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 clk: fix clk_get_rate() always return ulong

According to clk_ops struct definition, the callback get_rate() return current clock rate value as ulong.
clk_get_rate() should handle the clock rate returned as ulong also.

Otherwise we may have invalid/truncated clock rate value returned by clk_get_rate().

log_ret has also been removed since it use an int in the macro definition.

---
 drivers/clk/clk-uclass.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-uclass.c +2 -2
index b89c77bf79..446f7c49b8 100644
@@ -469,7 +469,7 @@ void clk_free(struct clk *clk)
 ulong clk_get_rate(struct clk *clk)
 {
 	const struct clk_ops *ops;
-	int ret;
+	ulong ret;
 
 	debug("%s(clk=%p)\n", __func__, clk);
 	if (!clk_valid(clk))
@@ -481,7 +481,7 @@ ulong clk_get_rate(struct clk *clk)
 
 	ret = ops->get_rate(clk);
 	if (ret)
-		return log_ret(ret);
+		return ret;
 
 	return 0;
 }
Signature · 1 line
2.37.2
#1 lore raw
Quoted 29 lines · Julien Masson

According to clk_ops struct definition, the callback get_rate() return current clock rate value as ulong.
clk_get_rate() should handle the clock rate returned as ulong also.

Otherwise we may have invalid/truncated clock rate value returned by clk_get_rate().

log_ret has also been removed since it use an int in the macro definition.

---
  drivers/clk/clk-uclass.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-uclass.c +1 -1
index b89c77bf79..446f7c49b8 100644
@@ -469,7 +469,7 @@ void clk_free(struct clk *clk)
  ulong clk_get_rate(struct clk *clk)
  {
  	const struct clk_ops *ops;
-	int ret;
+	ulong ret;
 
  	debug("%s(clk=%p)\n", __func__, clk);
  	if (!clk_valid(clk))

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 486

Quoted 7 lines
drivers/clk/clk-uclass.c +1 -1
@@ -481,7 +481,7 @@ ulong clk_get_rate(struct clk *clk)
 
  	ret = ops->get_rate(clk);
  	if (ret)
-		return log_ret(ret);
+		return ret;
 
  	return 0;

This can just be return ret no if required.

Quoted 2 lines
drivers/clk/clk-uclass.c +0 -0
  }
#2 lore raw

Hi,

Quoted 28 lines · Sean Anderson
Quoted 26 lines · Julien Masson

According to clk_ops struct definition, the callback get_rate() return current clock rate value as ulong.
clk_get_rate() should handle the clock rate returned as ulong also.

Otherwise we may have invalid/truncated clock rate value returned by clk_get_rate().

log_ret has also been removed since it use an int in the macro definition.

---
  drivers/clk/clk-uclass.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-uclass.c +1 -1
index b89c77bf79..446f7c49b8 100644
@@ -469,7 +469,7 @@ void clk_free(struct clk *clk)
  ulong clk_get_rate(struct clk *clk)
  {
      const struct clk_ops *ops;
-     int ret;
+     ulong ret;
 
Quoted 7 lines

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 484

Quoted 7 lines
drivers/clk/clk-uclass.c +0 -1
      debug("%s(clk=%p)\n", __func__, clk);
      if (!clk_valid(clk))
@@ -481,7 +481,7 @@ ulong clk_get_rate(struct clk *clk)
 
      ret = ops->get_rate(clk);
      if (ret)
-             return log_ret(ret);

How about:

if (IS_ERR(ret))
return log_ret(ret)

Quoted 5 lines

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 486

Quoted 3 lines
drivers/clk/clk-uclass.c +1 -0
+             return ret;
 
      return 0;

This can just be return ret no if required.

Yes, but it is nice to have the 'success' path clear and at the end.

Quoted 3 lines

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 487

Quoted 3 lines
drivers/clk/clk-uclass.c +0 -0
  }

Regards,
Simon

#3 lore raw
Quoted 35 lines · Simon Glass

Hi,

Quoted 32 lines · Sean Anderson
Quoted 30 lines · Julien Masson

According to clk_ops struct definition, the callback get_rate() return current clock rate value as ulong.
clk_get_rate() should handle the clock rate returned as ulong also.

Otherwise we may have invalid/truncated clock rate value returned by clk_get_rate().

log_ret has also been removed since it use an int in the macro definition.

---
  drivers/clk/clk-uclass.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-uclass.c +1 -1
index b89c77bf79..446f7c49b8 100644
@@ -469,7 +469,7 @@ void clk_free(struct clk *clk)
  ulong clk_get_rate(struct clk *clk)
  {
      const struct clk_ops *ops;
-     int ret;
+     ulong ret;
 
      debug("%s(clk=%p)\n", __func__, clk);
      if (!clk_valid(clk))
@@ -481,7 +481,7 @@ ulong clk_get_rate(struct clk *clk)
 
Quoted 8 lines
Quoted 3 lines

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 484

Quoted 3 lines
drivers/clk/clk-uclass.c +0 -1
      ret = ops->get_rate(clk);
      if (ret)
-             return log_ret(ret);

How about:

if (IS_ERR(ret))
return log_ret(ret)

Maybe we can let the caller do this check ?

This is how we do for these functions: clk_round_rate and clk_set_rate

Quoted 6 lines
Quoted 6 lines

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 486

Quoted 4 lines
drivers/clk/clk-uclass.c +1 -0
+             return ret;
 
      return 0;

This can just be return ret no if required.

Yes correct I can directly return the callback, I will change that in v2.

Quoted 2 lines

Yes, but it is nice to have the 'success' path clear and at the end.

hummm it's not clear to me if return 0 is considered as 'success' path. I guess some drivers doesn't expect to get 0 from a clock ...

As I suggested previously maybe we can let the caller handle the value returned by the callback ? (like clk_round_rate and clk_set_rate)

Quoted 7 lines
Quoted 4 lines

drivers/clk/clk-uclass.c ulong clk_get_rate(struct clk *clk) · line 487

Quoted 4 lines
drivers/clk/clk-uclass.c +0 -0
  }

Regards,
Simon

Signature · 1 line
Julien Masson