* [PATCH] sh: clk: Fix clk_enable() to return 0 on NULL clk
@ 2023-02-02 16:20 Geert Uytterhoeven
2023-02-02 16:28 ` John Paul Adrian Glaubitz
2023-02-02 23:17 ` Stephen Boyd
0 siblings, 2 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2023-02-02 16:20 UTC (permalink / raw)
To: Yoshinori Sato, Rich Felker, Michael Turquette, Stephen Boyd,
John Paul Adrian Glaubitz
Cc: linux-sh, linux-clk, Geert Uytterhoeven
On SH, devm_clk_get_optional_enabled() fails with -EINVAL if the clock
is not found. This happens because __devm_clk_get() assumes it can pass
a NULL clock pointer (as returned by clk_get_optional()) to the init()
function (clk_prepare_enable() in this case), while the SH
implementation of clk_enable() considers that an error.
Fix this by making the SH clk_enable() implementation return zero
instead, like the Common Clock Framework does.
Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Exposed by commit 599566c1c3692052 ("r8169: use
devm_clk_get_optional_enabled() to simplify the code"), cfr.
https://lore.kernel.org/all/585c4b48790d71ca43b66fc24ea8d84917c4a0e1.camel@physik.fu-berlin.de
Boot-tested on qemu/rts7751r2d, which did not show the problem though.
---
drivers/sh/clk/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index d996782a710642cd..7a73f5e4a1fc70cc 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -295,7 +295,7 @@ int clk_enable(struct clk *clk)
int ret;
if (!clk)
- return -EINVAL;
+ return 0;
spin_lock_irqsave(&clock_lock, flags);
ret = __clk_enable(clk);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sh: clk: Fix clk_enable() to return 0 on NULL clk
2023-02-02 16:20 [PATCH] sh: clk: Fix clk_enable() to return 0 on NULL clk Geert Uytterhoeven
@ 2023-02-02 16:28 ` John Paul Adrian Glaubitz
2023-02-02 23:17 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: John Paul Adrian Glaubitz @ 2023-02-02 16:28 UTC (permalink / raw)
To: Geert Uytterhoeven, Yoshinori Sato, Rich Felker,
Michael Turquette, Stephen Boyd
Cc: linux-sh, linux-clk
Hi Geert!
On Thu, 2023-02-02 at 17:20 +0100, Geert Uytterhoeven wrote:
> On SH, devm_clk_get_optional_enabled() fails with -EINVAL if the clock
> is not found. This happens because __devm_clk_get() assumes it can pass
> a NULL clock pointer (as returned by clk_get_optional()) to the init()
> function (clk_prepare_enable() in this case), while the SH
> implementation of clk_enable() considers that an error.
>
> Fix this by making the SH clk_enable() implementation return zero
> instead, like the Common Clock Framework does.
>
> Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> Exposed by commit 599566c1c3692052 ("r8169: use
> devm_clk_get_optional_enabled() to simplify the code"), cfr.
> https://lore.kernel.org/all/585c4b48790d71ca43b66fc24ea8d84917c4a0e1.camel@physik.fu-berlin.de
>
> Boot-tested on qemu/rts7751r2d, which did not show the problem though.
> ---
> drivers/sh/clk/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
> index d996782a710642cd..7a73f5e4a1fc70cc 100644
> --- a/drivers/sh/clk/core.c
> +++ b/drivers/sh/clk/core.c
> @@ -295,7 +295,7 @@ int clk_enable(struct clk *clk)
> int ret;
>
> if (!clk)
> - return -EINVAL;
> + return 0;
>
> spin_lock_irqsave(&clock_lock, flags);
> ret = __clk_enable(clk);
I can confirm that this patch makes the r8169 driver work again!
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Adrian
--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
`. `' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sh: clk: Fix clk_enable() to return 0 on NULL clk
2023-02-02 16:20 [PATCH] sh: clk: Fix clk_enable() to return 0 on NULL clk Geert Uytterhoeven
2023-02-02 16:28 ` John Paul Adrian Glaubitz
@ 2023-02-02 23:17 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2023-02-02 23:17 UTC (permalink / raw)
To: Geert Uytterhoeven, John Paul Adrian Glaubitz, Michael Turquette,
Rich Felker, Yoshinori Sato
Cc: linux-sh, linux-clk, Geert Uytterhoeven
Quoting Geert Uytterhoeven (2023-02-02 08:20:55)
> On SH, devm_clk_get_optional_enabled() fails with -EINVAL if the clock
> is not found. This happens because __devm_clk_get() assumes it can pass
> a NULL clock pointer (as returned by clk_get_optional()) to the init()
> function (clk_prepare_enable() in this case), while the SH
> implementation of clk_enable() considers that an error.
>
> Fix this by making the SH clk_enable() implementation return zero
> instead, like the Common Clock Framework does.
>
> Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
Acked-by: Stephen Boyd <sboyd@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-02 23:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 16:20 [PATCH] sh: clk: Fix clk_enable() to return 0 on NULL clk Geert Uytterhoeven
2023-02-02 16:28 ` John Paul Adrian Glaubitz
2023-02-02 23:17 ` Stephen Boyd
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.