Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] phy: ti-pipe3: Fix EPROBE_DEFER handling for clock resources
@ 2026-05-15  4:07 Hongling Zeng
  2026-05-15 15:58 ` Vladimir Oltean
  0 siblings, 1 reply; 3+ messages in thread
From: Hongling Zeng @ 2026-05-15  4:07 UTC (permalink / raw)
  To: vkoul, neil.armstrong, johan, kishon, rogerq
  Cc: linux-phy, linux-kernel, zhongling0719, Hongling Zeng

ti_pipe3_get_clk() has two issues with -EPROBE_DEFER error handling:

1. When devm_clk_get() for sysclk fails, the function returns -EINVAL
   instead of propagating the actual error code. This masks -EPROBE_DEFER
   to -EINVAL, breaking the probe deferral mechanism and causing permanent
   driver initialization failure on systems with non-deterministic probe
   ordering.

2. For SATA PHY refclk, the function ignores all errors to support older
   DTBs missing the refclk property. However, this incorrectly ignores
   -EPROBE_DEFER as well, causing the driver to proceed without waiting
   for the clock provider to become available.

Fix both issues:
- Return PTR_ERR(phy->sys_clk) instead of -EINVAL to propagate all
  error codes including -EPROBE_DEFER
- For SATA refclk, only ignore -ENOENT (clock not found in old DTBs)
  but propagate other errors like -EPROBE_DEFER

Fixes: a70143bbef6b ("drivers: phy: usb3/pipe3: Adapt pipe3 driver to Generic PHY Framework")
Fixes: 7f33912d2978 ("phy: ti-pipe3: Fix SATA across suspend/resume")
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
 drivers/phy/ti/phy-ti-pipe3.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c
index 58fbc3b27813..2bfcd0c70abd 100644
--- a/drivers/phy/ti/phy-ti-pipe3.c
+++ b/drivers/phy/ti/phy-ti-pipe3.c
@@ -604,15 +604,22 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
 {
 	struct clk *clk;
 	struct device *dev = phy->dev;
+	int ret;
 
 	phy->refclk = devm_clk_get(dev, "refclk");
 	if (IS_ERR(phy->refclk)) {
-		dev_err(dev, "unable to get refclk\n");
+		ret = PTR_ERR(phy->refclk);
 		/* older DTBs have missing refclk in SATA PHY
-		 * so don't bail out in case of SATA PHY.
+		 * so don't bail out for -ENOENT, but still defer
+		 * probe for other errors like -EPROBE_DEFER.
 		 */
-		if (phy->mode != PIPE3_MODE_SATA)
-			return PTR_ERR(phy->refclk);
+		if (ret == -ENOENT) {
+			if (phy->mode != PIPE3_MODE_SATA)
+				return ret;
+		} else {
+			dev_err(dev, "unable to get refclk\n");
+			return ret;
+		}
 	}
 
 	if (phy->mode != PIPE3_MODE_SATA) {
@@ -629,7 +636,7 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
 		phy->sys_clk = devm_clk_get(dev, "sysclk");
 		if (IS_ERR(phy->sys_clk)) {
 			dev_err(dev, "unable to get sysclk\n");
-			return -EINVAL;
+			return PTR_ERR(phy->sys_clk);
 		}
 	}
 
-- 
2.25.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH 2/2] phy: ti-pipe3: Fix EPROBE_DEFER handling for clock resources
  2026-05-15  4:07 [PATCH 2/2] phy: ti-pipe3: Fix EPROBE_DEFER handling for clock resources Hongling Zeng
@ 2026-05-15 15:58 ` Vladimir Oltean
  2026-05-18  2:22   ` Hongling Zeng
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Oltean @ 2026-05-15 15:58 UTC (permalink / raw)
  To: Hongling Zeng
  Cc: vkoul, neil.armstrong, johan, kishon, rogerq, linux-phy,
	linux-kernel, zhongling0719

On Fri, May 15, 2026 at 12:07:37PM +0800, Hongling Zeng wrote:
> ti_pipe3_get_clk() has two issues with -EPROBE_DEFER error handling:
> 
> 1. When devm_clk_get() for sysclk fails, the function returns -EINVAL
>    instead of propagating the actual error code. This masks -EPROBE_DEFER
>    to -EINVAL, breaking the probe deferral mechanism and causing permanent
>    driver initialization failure on systems with non-deterministic probe
>    ordering.
> 
> 2. For SATA PHY refclk, the function ignores all errors to support older
>    DTBs missing the refclk property. However, this incorrectly ignores
>    -EPROBE_DEFER as well, causing the driver to proceed without waiting
>    for the clock provider to become available.
> 
> Fix both issues:
> - Return PTR_ERR(phy->sys_clk) instead of -EINVAL to propagate all
>   error codes including -EPROBE_DEFER
> - For SATA refclk, only ignore -ENOENT (clock not found in old DTBs)
>   but propagate other errors like -EPROBE_DEFER
> 
> Fixes: a70143bbef6b ("drivers: phy: usb3/pipe3: Adapt pipe3 driver to Generic PHY Framework")
> Fixes: 7f33912d2978 ("phy: ti-pipe3: Fix SATA across suspend/resume")
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> ---
>  drivers/phy/ti/phy-ti-pipe3.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c
> index 58fbc3b27813..2bfcd0c70abd 100644
> --- a/drivers/phy/ti/phy-ti-pipe3.c
> +++ b/drivers/phy/ti/phy-ti-pipe3.c
> @@ -604,15 +604,22 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
>  {
>  	struct clk *clk;
>  	struct device *dev = phy->dev;
> +	int ret;
>  
>  	phy->refclk = devm_clk_get(dev, "refclk");

When phy->mode == PIPE3_MODE_SATA, I think it would be a good idea to
call devm_clk_get_optional() which converts ENOENT to 0 for you.
Otherwise call devm_clk_get(). In both cases, you can propagate the
returned error code without special-casing anything.

>  	if (IS_ERR(phy->refclk)) {
> -		dev_err(dev, "unable to get refclk\n");
> +		ret = PTR_ERR(phy->refclk);
>  		/* older DTBs have missing refclk in SATA PHY
> -		 * so don't bail out in case of SATA PHY.
> +		 * so don't bail out for -ENOENT, but still defer
> +		 * probe for other errors like -EPROBE_DEFER.
>  		 */
> -		if (phy->mode != PIPE3_MODE_SATA)
> -			return PTR_ERR(phy->refclk);
> +		if (ret == -ENOENT) {
> +			if (phy->mode != PIPE3_MODE_SATA)
> +				return ret;
> +		} else {
> +			dev_err(dev, "unable to get refclk\n");
> +			return ret;
> +		}
>  	}
>  
>  	if (phy->mode != PIPE3_MODE_SATA) {
> @@ -629,7 +636,7 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
>  		phy->sys_clk = devm_clk_get(dev, "sysclk");
>  		if (IS_ERR(phy->sys_clk)) {
>  			dev_err(dev, "unable to get sysclk\n");
> -			return -EINVAL;
> +			return PTR_ERR(phy->sys_clk);
>  		}
>  	}
>  
> -- 
> 2.25.1
> 
> 

Because of the broken threading this patch can't be applied anyway, so

pw-bot: cr

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

* Re: [PATCH 2/2] phy: ti-pipe3: Fix EPROBE_DEFER handling for clock resources
  2026-05-15 15:58 ` Vladimir Oltean
@ 2026-05-18  2:22   ` Hongling Zeng
  0 siblings, 0 replies; 3+ messages in thread
From: Hongling Zeng @ 2026-05-18  2:22 UTC (permalink / raw)
  To: Vladimir Oltean, Hongling Zeng
  Cc: vkoul, neil.armstrong, johan, kishon, rogerq, linux-phy,
	linux-kernel


在 2026年05月15日 23:58, Vladimir Oltean 写道:
> On Fri, May 15, 2026 at 12:07:37PM +0800, Hongling Zeng wrote:
>> ti_pipe3_get_clk() has two issues with -EPROBE_DEFER error handling:
>>
>> 1. When devm_clk_get() for sysclk fails, the function returns -EINVAL
>>     instead of propagating the actual error code. This masks -EPROBE_DEFER
>>     to -EINVAL, breaking the probe deferral mechanism and causing permanent
>>     driver initialization failure on systems with non-deterministic probe
>>     ordering.
>>
>> 2. For SATA PHY refclk, the function ignores all errors to support older
>>     DTBs missing the refclk property. However, this incorrectly ignores
>>     -EPROBE_DEFER as well, causing the driver to proceed without waiting
>>     for the clock provider to become available.
>>
>> Fix both issues:
>> - Return PTR_ERR(phy->sys_clk) instead of -EINVAL to propagate all
>>    error codes including -EPROBE_DEFER
>> - For SATA refclk, only ignore -ENOENT (clock not found in old DTBs)
>>    but propagate other errors like -EPROBE_DEFER
>>
>> Fixes: a70143bbef6b ("drivers: phy: usb3/pipe3: Adapt pipe3 driver to Generic PHY Framework")
>> Fixes: 7f33912d2978 ("phy: ti-pipe3: Fix SATA across suspend/resume")
>> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
>> ---
>>   drivers/phy/ti/phy-ti-pipe3.c | 17 ++++++++++++-----
>>   1 file changed, 12 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c
>> index 58fbc3b27813..2bfcd0c70abd 100644
>> --- a/drivers/phy/ti/phy-ti-pipe3.c
>> +++ b/drivers/phy/ti/phy-ti-pipe3.c
>> @@ -604,15 +604,22 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
>>   {
>>   	struct clk *clk;
>>   	struct device *dev = phy->dev;
>> +	int ret;
>>   
>>   	phy->refclk = devm_clk_get(dev, "refclk");
> When phy->mode == PIPE3_MODE_SATA, I think it would be a good idea to
> call devm_clk_get_optional() which converts ENOENT to 0 for you.
> Otherwise call devm_clk_get(). In both cases, you can propagate the
> returned error code without special-casing anything.
   Thank you for the review and suggestions.

   I've updated the patch to use devm_clk_get_optional() for SATA PHY
   refclk as suggested. This simplifies the error handling by automatically
   converting -ENOENT to NULL, allowing clean propagation of all other
   errors including -EPROBE_DEFER.

   I've also fixed the patch version numbering to v4 and ensured the
   patches are in the same series to avoid breaking Patchwork.

   Please see the attached v4 patch series.

>
>>   	if (IS_ERR(phy->refclk)) {
>> -		dev_err(dev, "unable to get refclk\n");
>> +		ret = PTR_ERR(phy->refclk);
>>   		/* older DTBs have missing refclk in SATA PHY
>> -		 * so don't bail out in case of SATA PHY.
>> +		 * so don't bail out for -ENOENT, but still defer
>> +		 * probe for other errors like -EPROBE_DEFER.
>>   		 */
>> -		if (phy->mode != PIPE3_MODE_SATA)
>> -			return PTR_ERR(phy->refclk);
>> +		if (ret == -ENOENT) {
>> +			if (phy->mode != PIPE3_MODE_SATA)
>> +				return ret;
>> +		} else {
>> +			dev_err(dev, "unable to get refclk\n");
>> +			return ret;
>> +		}
>>   	}
>>   
>>   	if (phy->mode != PIPE3_MODE_SATA) {
>> @@ -629,7 +636,7 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
>>   		phy->sys_clk = devm_clk_get(dev, "sysclk");
>>   		if (IS_ERR(phy->sys_clk)) {
>>   			dev_err(dev, "unable to get sysclk\n");
>> -			return -EINVAL;
>> +			return PTR_ERR(phy->sys_clk);
>>   		}
>>   	}
>>   
>> -- 
>> 2.25.1
>>
>>
> Because of the broken threading this patch can't be applied anyway, so
>
> pw-bot: cr


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

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

end of thread, other threads:[~2026-05-18  2:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-15  4:07 [PATCH 2/2] phy: ti-pipe3: Fix EPROBE_DEFER handling for clock resources Hongling Zeng
2026-05-15 15:58 ` Vladimir Oltean
2026-05-18  2:22   ` Hongling Zeng

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