mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] clk: have clk_get always return -ENOENT on missing clock
@ 2023-09-18 17:04 Ahmad Fatoum
  2023-09-21  8:02 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2023-09-18 17:04 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Currently, clk_get(dev, NULL) returns -ENOENT on missing clock, but 
clk_get(dev, "missing-named-clock") returns -EINVAL. This went by unnoticed
so far as most consumers either require a clock or don't, but with the
addition of clk_get_optional, it's important that clk_get() return value
is uniform.

Therefore align clk_get with Linux and always fall through to clk_get_sys()
if getting clock over DT is not possible. Failing clk_get_sys() returns
-ENOENT always, ensuring we can't end up with -EINVAL as before while
keeping of_clk_get_by_name return value as it is under Linux.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Please order before commit ("clk: implement clk_get_optional helper")
currently 8b013ac8ec69 in next.
---
 drivers/clk/clkdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 68c6ac36a0c8..dbe998b6af35 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -176,9 +176,9 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 	if (!IS_ERR(clk))
 		return clk;
 
-	if (dev) {
+	if (dev && dev->of_node) {
 		clk = of_clk_get_by_name(dev->of_node, con_id);
-		if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
+		if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
 			return clk;
 	}
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk: have clk_get always return -ENOENT on missing clock
  2023-09-18 17:04 [PATCH] clk: have clk_get always return -ENOENT on missing clock Ahmad Fatoum
@ 2023-09-21  8:02 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-09-21  8:02 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Sep 18, 2023 at 07:04:58PM +0200, Ahmad Fatoum wrote:
> Currently, clk_get(dev, NULL) returns -ENOENT on missing clock, but 
> clk_get(dev, "missing-named-clock") returns -EINVAL. This went by unnoticed
> so far as most consumers either require a clock or don't, but with the
> addition of clk_get_optional, it's important that clk_get() return value
> is uniform.
> 
> Therefore align clk_get with Linux and always fall through to clk_get_sys()
> if getting clock over DT is not possible. Failing clk_get_sys() returns
> -ENOENT always, ensuring we can't end up with -EINVAL as before while
> keeping of_clk_get_by_name return value as it is under Linux.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> Please order before commit ("clk: implement clk_get_optional helper")
> currently 8b013ac8ec69 in next.
> ---
>  drivers/clk/clkdev.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
> index 68c6ac36a0c8..dbe998b6af35 100644
> --- a/drivers/clk/clkdev.c
> +++ b/drivers/clk/clkdev.c
> @@ -176,9 +176,9 @@ struct clk *clk_get(struct device *dev, const char *con_id)
>  	if (!IS_ERR(clk))
>  		return clk;
>  
> -	if (dev) {
> +	if (dev && dev->of_node) {
>  		clk = of_clk_get_by_name(dev->of_node, con_id);
> -		if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
> +		if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
>  			return clk;
>  	}
>  
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-21  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18 17:04 [PATCH] clk: have clk_get always return -ENOENT on missing clock Ahmad Fatoum
2023-09-21  8:02 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox