Re: [PATCH] serial: sprd: Return -EPROBE_DEFER when uart clock is not ready
From: wenhua lin
Date: Thu Nov 27 2025 - 03:44:20 EST
On Wed, Nov 26, 2025 at 8:57 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxx> 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
>
>