* [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
@ 2025-10-22 3:08 Wenhua Lin
2025-10-22 6:55 ` Chunyan Zhang
2025-11-26 12:57 ` Andy Shevchenko
0 siblings, 2 replies; 9+ messages in thread
From: Wenhua Lin @ 2025-10-22 3:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley
Cc: Orson Zhai, Baolin Wang, Chunyan Zhang, Cixi Geng, linux-kernel,
linux-serial, wenhua lin, Wenhua Lin, Xiongpeng Wu, Zhaochen Su,
Zhirong Qiu
In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
for either uart or source clock, we should propagate the
error instead of just warning and continuing with NULL clocks.
Currently the driver only emits a warning when clock acquisition
fails and proceeds with NULL clock pointers. This can lead to
issues later when the clocks are actually needed. More importantly,
when the clock provider is not ready yet and returns -EPROBE_DEFER,
we should return this error to allow deferred probing.
This change adds explicit checks for -EPROBE_DEFER after both:
1. devm_clk_get(uport->dev, uart)
2. devm_clk_get(uport->dev, source)
When -EPROBE_DEFER is encountered, the function now returns
-EPROBE_DEFER to let the driver framework retry probing
later when the clock dependencies are resolved.
Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
---
drivers/tty/serial/sprd_serial.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index 8c9366321f8e..092755f35683 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -1133,6 +1133,9 @@ static int sprd_clk_init(struct uart_port *uport)
clk_uart = devm_clk_get(uport->dev, "uart");
if (IS_ERR(clk_uart)) {
+ if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
dev_warn(uport->dev, "uart%d can't get uart clock\n",
uport->line);
clk_uart = NULL;
@@ -1140,6 +1143,9 @@ static int sprd_clk_init(struct uart_port *uport)
clk_parent = devm_clk_get(uport->dev, "source");
if (IS_ERR(clk_parent)) {
+ if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
dev_warn(uport->dev, "uart%d can't get source clock\n",
uport->line);
clk_parent = NULL;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-10-22 3:08 [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready Wenhua Lin
@ 2025-10-22 6:55 ` Chunyan Zhang
2025-10-23 2:10 ` wenhua lin
2025-11-26 12:57 ` Andy Shevchenko
1 sibling, 1 reply; 9+ messages in thread
From: Chunyan Zhang @ 2025-10-22 6:55 UTC (permalink / raw)
To: Wenhua Lin
Cc: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Orson Zhai, Baolin Wang, Cixi Geng, linux-kernel,
linux-serial, wenhua lin, Xiongpeng Wu, Zhaochen Su, Zhirong Qiu
On Wed, 22 Oct 2025 at 11:09, Wenhua Lin <Wenhua.Lin@unisoc.com> wrote:
>
> In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
> for either uart or source clock, we should propagate the
> error instead of just warning and continuing with NULL clocks.
>
> Currently the driver only emits a warning when clock acquisition
> fails and proceeds with NULL clock pointers. This can lead to
> issues later when the clocks are actually needed. More importantly,
> when the clock provider is not ready yet and returns -EPROBE_DEFER,
> we should return this error to allow deferred probing.
>
> This change adds explicit checks for -EPROBE_DEFER after both:
> 1. devm_clk_get(uport->dev, uart)
> 2. devm_clk_get(uport->dev, source)
>
> When -EPROBE_DEFER is encountered, the function now returns
> -EPROBE_DEFER to let the driver framework retry probing
> later when the clock dependencies are resolved.
>
> Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> ---
> drivers/tty/serial/sprd_serial.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> index 8c9366321f8e..092755f35683 100644
> --- a/drivers/tty/serial/sprd_serial.c
> +++ b/drivers/tty/serial/sprd_serial.c
> @@ -1133,6 +1133,9 @@ static int sprd_clk_init(struct uart_port *uport)
>
> clk_uart = devm_clk_get(uport->dev, "uart");
> if (IS_ERR(clk_uart)) {
> + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> +
You are making this clock mandatory, sprd_serial driver could work as
serial ports for logs output without this "uart" clock.
> dev_warn(uport->dev, "uart%d can't get uart clock\n",
> uport->line);
> clk_uart = NULL;
> @@ -1140,6 +1143,9 @@ static int sprd_clk_init(struct uart_port *uport)
>
> clk_parent = devm_clk_get(uport->dev, "source");
> if (IS_ERR(clk_parent)) {
> + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> +
> dev_warn(uport->dev, "uart%d can't get source clock\n",
> uport->line);
> clk_parent = NULL;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-10-22 6:55 ` Chunyan Zhang
@ 2025-10-23 2:10 ` wenhua lin
2025-10-24 1:42 ` Chunyan Zhang
0 siblings, 1 reply; 9+ messages in thread
From: wenhua lin @ 2025-10-23 2:10 UTC (permalink / raw)
To: Chunyan Zhang
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Orson Zhai,
Baolin Wang, Cixi Geng, linux-kernel, linux-serial, Xiongpeng Wu,
Zhaochen Su, Zhirong Qiu
On Wed, Oct 22, 2025 at 2:55 PM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> On Wed, 22 Oct 2025 at 11:09, Wenhua Lin <Wenhua.Lin@unisoc.com> wrote:
> >
> > In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
> > for either uart or source clock, we should propagate the
> > error instead of just warning and continuing with NULL clocks.
> >
> > Currently the driver only emits a warning when clock acquisition
> > fails and proceeds with NULL clock pointers. This can lead to
> > issues later when the clocks are actually needed. More importantly,
> > when the clock provider is not ready yet and returns -EPROBE_DEFER,
> > we should return this error to allow deferred probing.
> >
> > This change adds explicit checks for -EPROBE_DEFER after both:
> > 1. devm_clk_get(uport->dev, uart)
> > 2. devm_clk_get(uport->dev, source)
> >
> > When -EPROBE_DEFER is encountered, the function now returns
> > -EPROBE_DEFER to let the driver framework retry probing
> > later when the clock dependencies are resolved.
> >
> > Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> > ---
> > drivers/tty/serial/sprd_serial.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> > index 8c9366321f8e..092755f35683 100644
> > --- a/drivers/tty/serial/sprd_serial.c
> > +++ b/drivers/tty/serial/sprd_serial.c
> > @@ -1133,6 +1133,9 @@ static int sprd_clk_init(struct uart_port *uport)
> >
> > clk_uart = devm_clk_get(uport->dev, "uart");
> > if (IS_ERR(clk_uart)) {
> > + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> > + return -EPROBE_DEFER;
> > +
>
> You are making this clock mandatory, sprd_serial driver could work as
> serial ports for logs output without this "uart" clock.
Hi chunyan:
Thank you very much for your review.
This clock is actually mandatory now,some SPRD project use default 26M clock,
some new SPRD project use default 24M clock. If driver can't parse
this clock correctly,
driver will configure wrong baudrate and make the log garbled.
Thanks
>
> > dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > uport->line);
> > clk_uart = NULL;
> > @@ -1140,6 +1143,9 @@ static int sprd_clk_init(struct uart_port *uport)
> >
> > clk_parent = devm_clk_get(uport->dev, "source");
> > if (IS_ERR(clk_parent)) {
> > + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> > + return -EPROBE_DEFER;
> > +
> > dev_warn(uport->dev, "uart%d can't get source clock\n",
> > uport->line);
> > clk_parent = NULL;
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-10-23 2:10 ` wenhua lin
@ 2025-10-24 1:42 ` Chunyan Zhang
2025-11-10 3:05 ` wenhua lin
0 siblings, 1 reply; 9+ messages in thread
From: Chunyan Zhang @ 2025-10-24 1:42 UTC (permalink / raw)
To: wenhua lin
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Orson Zhai,
Baolin Wang, Cixi Geng, linux-kernel, linux-serial, Xiongpeng Wu,
Zhaochen Su, Zhirong Qiu
Hi Wenhua,
On Thu, 23 Oct 2025 at 10:10, wenhua lin <wenhua.lin1994@gmail.com> wrote:
>
> On Wed, Oct 22, 2025 at 2:55 PM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
> >
> > On Wed, 22 Oct 2025 at 11:09, Wenhua Lin <Wenhua.Lin@unisoc.com> wrote:
> > >
> > > In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
> > > for either uart or source clock, we should propagate the
> > > error instead of just warning and continuing with NULL clocks.
> > >
> > > Currently the driver only emits a warning when clock acquisition
> > > fails and proceeds with NULL clock pointers. This can lead to
> > > issues later when the clocks are actually needed. More importantly,
> > > when the clock provider is not ready yet and returns -EPROBE_DEFER,
> > > we should return this error to allow deferred probing.
> > >
> > > This change adds explicit checks for -EPROBE_DEFER after both:
> > > 1. devm_clk_get(uport->dev, uart)
> > > 2. devm_clk_get(uport->dev, source)
> > >
> > > When -EPROBE_DEFER is encountered, the function now returns
> > > -EPROBE_DEFER to let the driver framework retry probing
> > > later when the clock dependencies are resolved.
> > >
> > > Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> > > ---
> > > drivers/tty/serial/sprd_serial.c | 6 ++++++
> > > 1 file changed, 6 insertions(+)
> > >
> > > diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> > > index 8c9366321f8e..092755f35683 100644
> > > --- a/drivers/tty/serial/sprd_serial.c
> > > +++ b/drivers/tty/serial/sprd_serial.c
> > > @@ -1133,6 +1133,9 @@ static int sprd_clk_init(struct uart_port *uport)
> > >
> > > clk_uart = devm_clk_get(uport->dev, "uart");
> > > if (IS_ERR(clk_uart)) {
> > > + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> > > + return -EPROBE_DEFER;
> > > +
> >
> > You are making this clock mandatory, sprd_serial driver could work as
> > serial ports for logs output without this "uart" clock.
>
> Hi chunyan:
> Thank you very much for your review.
> This clock is actually mandatory now,some SPRD project use default 26M clock,
> some new SPRD project use default 24M clock. If driver can't parse
Oh I see, then you can set a different default clock according to the
compatible string, that's saying make SPRD_DEFAULT_SOURCE_CLK to be an
element of "of_device_id.data".
Thanks,
Chunyan
> this clock correctly,
> driver will configure wrong baudrate and make the log garbled.
>
> Thanks
>
> >
> > > dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > > uport->line);
> > > clk_uart = NULL;
> > > @@ -1140,6 +1143,9 @@ static int sprd_clk_init(struct uart_port *uport)
> > >
> > > clk_parent = devm_clk_get(uport->dev, "source");
> > > if (IS_ERR(clk_parent)) {
> > > + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> > > + return -EPROBE_DEFER;
> > > +
> > > dev_warn(uport->dev, "uart%d can't get source clock\n",
> > > uport->line);
> > > clk_parent = NULL;
> > > --
> > > 2.34.1
> > >
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-10-24 1:42 ` Chunyan Zhang
@ 2025-11-10 3:05 ` wenhua lin
0 siblings, 0 replies; 9+ messages in thread
From: wenhua lin @ 2025-11-10 3:05 UTC (permalink / raw)
To: Chunyan Zhang
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Orson Zhai,
Baolin Wang, Cixi Geng, linux-kernel, linux-serial, Xiongpeng Wu,
Zhaochen Su, Zhirong Qiu
On Fri, Oct 24, 2025 at 9:42 AM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> Hi Wenhua,
>
> On Thu, 23 Oct 2025 at 10:10, wenhua lin <wenhua.lin1994@gmail.com> wrote:
> >
> > On Wed, Oct 22, 2025 at 2:55 PM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
> > >
> > > On Wed, 22 Oct 2025 at 11:09, Wenhua Lin <Wenhua.Lin@unisoc.com> wrote:
> > > >
> > > > In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
> > > > for either uart or source clock, we should propagate the
> > > > error instead of just warning and continuing with NULL clocks.
> > > >
> > > > Currently the driver only emits a warning when clock acquisition
> > > > fails and proceeds with NULL clock pointers. This can lead to
> > > > issues later when the clocks are actually needed. More importantly,
> > > > when the clock provider is not ready yet and returns -EPROBE_DEFER,
> > > > we should return this error to allow deferred probing.
> > > >
> > > > This change adds explicit checks for -EPROBE_DEFER after both:
> > > > 1. devm_clk_get(uport->dev, uart)
> > > > 2. devm_clk_get(uport->dev, source)
> > > >
> > > > When -EPROBE_DEFER is encountered, the function now returns
> > > > -EPROBE_DEFER to let the driver framework retry probing
> > > > later when the clock dependencies are resolved.
> > > >
> > > > Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> > > > ---
> > > > drivers/tty/serial/sprd_serial.c | 6 ++++++
> > > > 1 file changed, 6 insertions(+)
> > > >
> > > > diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> > > > index 8c9366321f8e..092755f35683 100644
> > > > --- a/drivers/tty/serial/sprd_serial.c
> > > > +++ b/drivers/tty/serial/sprd_serial.c
> > > > @@ -1133,6 +1133,9 @@ static int sprd_clk_init(struct uart_port *uport)
> > > >
> > > > clk_uart = devm_clk_get(uport->dev, "uart");
> > > > if (IS_ERR(clk_uart)) {
> > > > + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> > > > + return -EPROBE_DEFER;
> > > > +
> > >
> > > You are making this clock mandatory, sprd_serial driver could work as
> > > serial ports for logs output without this "uart" clock.
> >
> > Hi chunyan:
> > Thank you very much for your review.
> > This clock is actually mandatory now,some SPRD project use default 26M clock,
> > some new SPRD project use default 24M clock. If driver can't parse
>
> Oh I see, then you can set a different default clock according to the
> compatible string, that's saying make SPRD_DEFAULT_SOURCE_CLK to be an
> element of "of_device_id.data".
>
> Thanks,
> Chunyan
Hi chunyan:
This is not the current issue; it will be considered in future modifications.
The main reason for this change is that the UART driver is
built-in, while the CLK driver is loaded as a module (ko).
There may be a situation where the UART driver is loaded first.
If an EPROBE_DEFER error occurs, the driver will return directly
and continue waiting for the CLK driver to complete loading.
Thanks
>
> > this clock correctly,
> > driver will configure wrong baudrate and make the log garbled.
> >
> > Thanks
> >
> > >
> > > > dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > > > uport->line);
> > > > clk_uart = NULL;
> > > > @@ -1140,6 +1143,9 @@ static int sprd_clk_init(struct uart_port *uport)
> > > >
> > > > clk_parent = devm_clk_get(uport->dev, "source");
> > > > if (IS_ERR(clk_parent)) {
> > > > + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> > > > + return -EPROBE_DEFER;
> > > > +
> > > > dev_warn(uport->dev, "uart%d can't get source clock\n",
> > > > uport->line);
> > > > clk_parent = NULL;
> > > > --
> > > > 2.34.1
> > > >
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-10-22 3:08 [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready Wenhua Lin
2025-10-22 6:55 ` Chunyan Zhang
@ 2025-11-26 12:57 ` Andy Shevchenko
2025-11-27 8:44 ` wenhua lin
1 sibling, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-11-26 12:57 UTC (permalink / raw)
To: Wenhua Lin
Cc: Greg Kroah-Hartman, Jiri Slaby, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Orson Zhai, Baolin Wang, Chunyan Zhang, Cixi Geng,
linux-kernel, linux-serial, wenhua lin, Xiongpeng Wu, Zhaochen Su,
Zhirong Qiu
On Wed, Oct 22, 2025 at 11:08:40AM +0800, Wenhua Lin wrote:
> In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
> for either uart or source clock, we should propagate the
> error instead of just warning and continuing with NULL clocks.
>
> Currently the driver only emits a warning when clock acquisition
> fails and proceeds with NULL clock pointers. This can lead to
> issues later when the clocks are actually needed. More importantly,
> when the clock provider is not ready yet and returns -EPROBE_DEFER,
> we should return this error to allow deferred probing.
>
> This change adds explicit checks for -EPROBE_DEFER after both:
> 1. devm_clk_get(uport->dev, uart)
> 2. devm_clk_get(uport->dev, source)
>
> When -EPROBE_DEFER is encountered, the function now returns
> -EPROBE_DEFER to let the driver framework retry probing
> later when the clock dependencies are resolved.
...
> clk_uart = devm_clk_get(uport->dev, "uart");
> if (IS_ERR(clk_uart)) {
> + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> +
> dev_warn(uport->dev, "uart%d can't get uart clock\n",
> uport->line);
> clk_uart = NULL;
AFAICS this still ignores other issues, what should be done here is to
replace devm_clk_get() by devm_clk_get_optional() and drop this NULL
assignment.
...
> clk_parent = devm_clk_get(uport->dev, "source");
> if (IS_ERR(clk_parent)) {
> + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> +
> dev_warn(uport->dev, "uart%d can't get source clock\n",
> uport->line);
> clk_parent = NULL;
Ditto.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-11-26 12:57 ` Andy Shevchenko
@ 2025-11-27 8:44 ` wenhua lin
2025-11-27 9:05 ` Andy Shevchenko
0 siblings, 1 reply; 9+ messages in thread
From: wenhua lin @ 2025-11-27 8:44 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Orson Zhai, Baolin Wang,
Chunyan Zhang, Cixi Geng, linux-kernel, linux-serial,
Xiongpeng Wu, Zhaochen Su, Zhirong Qiu
On Wed, Nov 26, 2025 at 8:57 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Wed, Oct 22, 2025 at 11:08:40AM +0800, Wenhua Lin wrote:
> > In sprd_clk_init(), when devm_clk_get() returns -EPROBE_DEFER
> > for either uart or source clock, we should propagate the
> > error instead of just warning and continuing with NULL clocks.
> >
> > Currently the driver only emits a warning when clock acquisition
> > fails and proceeds with NULL clock pointers. This can lead to
> > issues later when the clocks are actually needed. More importantly,
> > when the clock provider is not ready yet and returns -EPROBE_DEFER,
> > we should return this error to allow deferred probing.
> >
> > This change adds explicit checks for -EPROBE_DEFER after both:
> > 1. devm_clk_get(uport->dev, uart)
> > 2. devm_clk_get(uport->dev, source)
> >
> > When -EPROBE_DEFER is encountered, the function now returns
> > -EPROBE_DEFER to let the driver framework retry probing
> > later when the clock dependencies are resolved.
>
> ...
>
> > clk_uart = devm_clk_get(uport->dev, "uart");
> > if (IS_ERR(clk_uart)) {
> > + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> > + return -EPROBE_DEFER;
> > +
> > dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > uport->line);
> > clk_uart = NULL;
>
> AFAICS this still ignores other issues, what should be done here is to
> replace devm_clk_get() by devm_clk_get_optional() and drop this NULL
> assignment.
>
> ...
Hi Andy:
The main reason for this change is that the UART driver is
built-in, while the CLK driver is loaded as a module (ko).
There may be a situation where the UART driver is loaded first. If
an EPROBE_DEFER error occurs, the driver will return directly
and continue waiting for the CLK driver to complete loading.
If this interface is changed to devm_clk_get_optional, in scenarios
where dependent components are not yet loaded,
it will no longer return EPROBE_DEFER but instead return null. This
behavior may not align with the desired outcome.
Thanks
>
> > clk_parent = devm_clk_get(uport->dev, "source");
> > if (IS_ERR(clk_parent)) {
> > + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> > + return -EPROBE_DEFER;
> > +
> > dev_warn(uport->dev, "uart%d can't get source clock\n",
> > uport->line);
> > clk_parent = NULL;
>
> Ditto.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-11-27 8:44 ` wenhua lin
@ 2025-11-27 9:05 ` Andy Shevchenko
2025-12-10 6:48 ` wenhua lin
0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2025-11-27 9:05 UTC (permalink / raw)
To: wenhua lin
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Orson Zhai, Baolin Wang,
Chunyan Zhang, Cixi Geng, linux-kernel, linux-serial,
Xiongpeng Wu, Zhaochen Su, Zhirong Qiu
On Thu, Nov 27, 2025 at 04:44:08PM +0800, wenhua lin wrote:
> On Wed, Nov 26, 2025 at 8:57 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> > On Wed, Oct 22, 2025 at 11:08:40AM +0800, Wenhua Lin wrote:
...
> > > clk_uart = devm_clk_get(uport->dev, "uart");
> > > if (IS_ERR(clk_uart)) {
> > > + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> > > + return -EPROBE_DEFER;
> > > +
> > > dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > > uport->line);
> > > clk_uart = NULL;
> >
> > AFAICS this still ignores other issues, what should be done here is to
> > replace devm_clk_get() by devm_clk_get_optional() and drop this NULL
> > assignment.
> The main reason for this change is that the UART driver is
> built-in, while the CLK driver is loaded as a module (ko).
> There may be a situation where the UART driver is loaded first. If
> an EPROBE_DEFER error occurs, the driver will return directly
> and continue waiting for the CLK driver to complete loading.
> If this interface is changed to devm_clk_get_optional, in scenarios
> where dependent components are not yet loaded,
> it will no longer return EPROBE_DEFER but instead return null. This
> behavior may not align with the desired outcome.
No, the _optional does exactly what your code does with the better approach
that may return other errors _in addition to_ the current state of affairs.
So, please switch to _optional variant and drop all that unneeded dances.
clk_uart = devm_clk_get_optional(uport->dev, "uart");
if (IS_ERR(clk_uart)) {
return dev_err_probe(uport->dev, PTR_ERR(clk_uart),
"uart%d can't get uart clock\n", uport->line);
this will return an error when clock is present, but can't be retrieved.
When there is no clock provided at all, it will return NULL.
> > > clk_parent = devm_clk_get(uport->dev, "source");
> > > if (IS_ERR(clk_parent)) {
> > > + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> > > + return -EPROBE_DEFER;
> > > +
> > > dev_warn(uport->dev, "uart%d can't get source clock\n",
> > > uport->line);
> > > clk_parent = NULL;
Ditto.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
2025-11-27 9:05 ` Andy Shevchenko
@ 2025-12-10 6:48 ` wenhua lin
0 siblings, 0 replies; 9+ messages in thread
From: wenhua lin @ 2025-12-10 6:48 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Orson Zhai, Baolin Wang,
Chunyan Zhang, Cixi Geng, linux-kernel, linux-serial,
Xiongpeng Wu, Zhaochen Su, Zhirong Qiu
On Thu, Nov 27, 2025 at 5:05 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Thu, Nov 27, 2025 at 04:44:08PM +0800, wenhua lin wrote:
> > On Wed, Nov 26, 2025 at 8:57 PM Andy Shevchenko
> > <andriy.shevchenko@intel.com> wrote:
> > > On Wed, Oct 22, 2025 at 11:08:40AM +0800, Wenhua Lin wrote:
>
> ...
>
> > > > clk_uart = devm_clk_get(uport->dev, "uart");
> > > > if (IS_ERR(clk_uart)) {
> > > > + if (PTR_ERR(clk_uart) == -EPROBE_DEFER)
> > > > + return -EPROBE_DEFER;
> > > > +
> > > > dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > > > uport->line);
> > > > clk_uart = NULL;
> > >
> > > AFAICS this still ignores other issues, what should be done here is to
> > > replace devm_clk_get() by devm_clk_get_optional() and drop this NULL
> > > assignment.
>
> > The main reason for this change is that the UART driver is
> > built-in, while the CLK driver is loaded as a module (ko).
> > There may be a situation where the UART driver is loaded first. If
> > an EPROBE_DEFER error occurs, the driver will return directly
> > and continue waiting for the CLK driver to complete loading.
> > If this interface is changed to devm_clk_get_optional, in scenarios
> > where dependent components are not yet loaded,
> > it will no longer return EPROBE_DEFER but instead return null. This
> > behavior may not align with the desired outcome.
>
> No, the _optional does exactly what your code does with the better approach
> that may return other errors _in addition to_ the current state of affairs.
>
> So, please switch to _optional variant and drop all that unneeded dances.
>
> clk_uart = devm_clk_get_optional(uport->dev, "uart");
> if (IS_ERR(clk_uart)) {
> return dev_err_probe(uport->dev, PTR_ERR(clk_uart),
> "uart%d can't get uart clock\n", uport->line);
>
> this will return an error when clock is present, but can't be retrieved.
> When there is no clock provided at all, it will return NULL.
>
> > > > clk_parent = devm_clk_get(uport->dev, "source");
> > > > if (IS_ERR(clk_parent)) {
> > > > + if (PTR_ERR(clk_parent) == -EPROBE_DEFER)
> > > > + return -EPROBE_DEFER;
> > > > +
> > > > dev_warn(uport->dev, "uart%d can't get source clock\n",
> > > > uport->line);
> > > > clk_parent = NULL;
>
> Ditto.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
Hi Andy:
Thank you for your valuable feedback.
We have implemented the changes in patch V2 and submitted a revised version.
Thanks
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-12-10 6:48 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 3:08 [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready Wenhua Lin
2025-10-22 6:55 ` Chunyan Zhang
2025-10-23 2:10 ` wenhua lin
2025-10-24 1:42 ` Chunyan Zhang
2025-11-10 3:05 ` wenhua lin
2025-11-26 12:57 ` Andy Shevchenko
2025-11-27 8:44 ` wenhua lin
2025-11-27 9:05 ` Andy Shevchenko
2025-12-10 6:48 ` wenhua lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).