[PATCH] phy: ti: da8xx-usb: Handle devm_pm_runtime_enable() errors

Haotian Zhang posted 1 patch 1 week ago
There is a newer version of this series
drivers/phy/ti/phy-da8xx-usb.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
[PATCH] phy: ti: da8xx-usb: Handle devm_pm_runtime_enable() errors
Posted by Haotian Zhang 1 week ago
devm_pm_runtime_enable() can fail due to memory allocation. The current
code ignores its return value after calling pm_runtime_set_active(),
leaving the device in an inconsistent state if runtime PM initialization
fails.

Check the return value of devm_pm_runtime_enable() and return on
failure. Also move the declaration of 'ret' to the function scope
to support this check.

Fixes: ee8e41b5044f ("phy: ti: phy-da8xx-usb: Add runtime PM support")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/phy/ti/phy-da8xx-usb.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/ti/phy-da8xx-usb.c b/drivers/phy/ti/phy-da8xx-usb.c
index 1d81a1e6ec6b..be9c77f8c288 100644
--- a/drivers/phy/ti/phy-da8xx-usb.c
+++ b/drivers/phy/ti/phy-da8xx-usb.c
@@ -180,6 +180,7 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
 	struct da8xx_usb_phy_platform_data *pdata = dev->platform_data;
 	struct device_node	*node = dev->of_node;
 	struct da8xx_usb_phy	*d_phy;
+	int ret;
 
 	d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL);
 	if (!d_phy)
@@ -233,8 +234,6 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
 			return PTR_ERR(d_phy->phy_provider);
 		}
 	} else {
-		int ret;
-
 		ret = phy_create_lookup(d_phy->usb11_phy, "usb-phy",
 					"ohci-da8xx");
 		if (ret)
@@ -249,7 +248,11 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
 			  PHY_INIT_BITS, PHY_INIT_BITS);
 
 	pm_runtime_set_active(dev);
-	devm_pm_runtime_enable(dev);
+	ret = devm_pm_runtime_enable(dev);
+	if (ret) {
+		dev_err(dev, "Failed to enable runtime PM\n");
+		return ret;
+	}
 	/*
 	 * Prevent runtime pm from being ON by default. Users can enable
 	 * it using power/control in sysfs.
-- 
2.50.1.windows.1
Re: [PATCH] phy: ti: da8xx-usb: Handle devm_pm_runtime_enable() errors
Posted by Neil Armstrong 1 week ago
On 11/24/25 02:19, Haotian Zhang wrote:
> devm_pm_runtime_enable() can fail due to memory allocation. The current
> code ignores its return value after calling pm_runtime_set_active(),
> leaving the device in an inconsistent state if runtime PM initialization
> fails.
> 
> Check the return value of devm_pm_runtime_enable() and return on
> failure. Also move the declaration of 'ret' to the function scope
> to support this check.
> 
> Fixes: ee8e41b5044f ("phy: ti: phy-da8xx-usb: Add runtime PM support")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
>   drivers/phy/ti/phy-da8xx-usb.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/phy/ti/phy-da8xx-usb.c b/drivers/phy/ti/phy-da8xx-usb.c
> index 1d81a1e6ec6b..be9c77f8c288 100644
> --- a/drivers/phy/ti/phy-da8xx-usb.c
> +++ b/drivers/phy/ti/phy-da8xx-usb.c
> @@ -180,6 +180,7 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
>   	struct da8xx_usb_phy_platform_data *pdata = dev->platform_data;
>   	struct device_node	*node = dev->of_node;
>   	struct da8xx_usb_phy	*d_phy;
> +	int ret;
>   
>   	d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL);
>   	if (!d_phy)
> @@ -233,8 +234,6 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
>   			return PTR_ERR(d_phy->phy_provider);
>   		}
>   	} else {
> -		int ret;
> -
>   		ret = phy_create_lookup(d_phy->usb11_phy, "usb-phy",
>   					"ohci-da8xx");
>   		if (ret)
> @@ -249,7 +248,11 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
>   			  PHY_INIT_BITS, PHY_INIT_BITS);
>   
>   	pm_runtime_set_active(dev);
> -	devm_pm_runtime_enable(dev);
> +	ret = devm_pm_runtime_enable(dev);
> +	if (ret) {
> +		dev_err(dev, "Failed to enable runtime PM\n");
> +		return ret;
> +	}

As the error would only be -ENOMEM, just return ret and drop the dev_err().

Neil

>   	/*
>   	 * Prevent runtime pm from being ON by default. Users can enable
>   	 * it using power/control in sysfs.