Skip to contentSkip to conversation

usb: dwc3: xilinx: improve error handling for PM APIs

PATCH In review Piyush Mehta 3 participants 4 messages Nov 8, 2023 – Dec 5, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: xilinx: improve error handling for PM APIs

Improve error handling for PM APIs in the dwc3_xlnx_probe function by introducing devm_pm_runtime_enable and error label. Removed unnecessary API pm_runtime_disable call in dwc3_xlnx_remove.

---
 drivers/usb/dwc3/dwc3-xilinx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-xilinx.c +7 -3
index 5b7e92f476de..9cf26e9a1c3d 100644
@@ -294,10 +294,15 @@ static int dwc3_xlnx_probe(struct platform_device *pdev)
 
 	pm_runtime_set_active(dev);
 	pm_runtime_enable(dev);
+	ret = devm_pm_runtime_enable(dev);
+	if (ret < 0)
+		goto err_pm_set_suspended;
+
 	pm_suspend_ignore_children(dev, false);
-	pm_runtime_get_sync(dev);
+	return pm_runtime_resume_and_get(dev);
 
-	return 0;
+err_pm_set_suspended:
+	pm_runtime_set_suspended(dev);
 
 err_clk_put:
 	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
@@ -315,7 +320,6 @@ static void dwc3_xlnx_remove(struct platform_device *pdev)
 	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
 	priv_data->num_clocks = 0;
 
-	pm_runtime_disable(dev);
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);
 }
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 14 lines · Piyush Mehta

Improve error handling for PM APIs in the dwc3_xlnx_probe function by introducing devm_pm_runtime_enable and error label. Removed unnecessary API pm_runtime_disable call in dwc3_xlnx_remove.

---
 drivers/usb/dwc3/dwc3-xilinx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-xilinx.c +0 -0
index 5b7e92f476de..9cf26e9a1c3d 100644

drivers/usb/dwc3/dwc3-xilinx.c static int dwc3_xlnx_probe(struct platform_device *pdev) · line 297

Quoted 4 lines
drivers/usb/dwc3/dwc3-xilinx.c +1 -0
@@ -294,10 +294,15 @@ static int dwc3_xlnx_probe(struct platform_device *pdev)
 
 	pm_runtime_set_active(dev);
 	pm_runtime_enable(dev);
+	ret = devm_pm_runtime_enable(dev);

You just did pm_runtime_enable() right above, why
devm_pm_runtime_enable() again?

drivers/usb/dwc3/dwc3-xilinx.c static int dwc3_xlnx_probe(struct platform_device *pdev) · line 305

Quoted 10 lines
drivers/usb/dwc3/dwc3-xilinx.c +6 -2
+	if (ret < 0)
+		goto err_pm_set_suspended;
+
 	pm_suspend_ignore_children(dev, false);
-	pm_runtime_get_sync(dev);
+	return pm_runtime_resume_and_get(dev);
 
-	return 0;
+err_pm_set_suspended:
+	pm_runtime_set_suspended(dev);

This doesn't look right. why set status suspended here?

BR,
Thinh

Quoted 14 lines
drivers/usb/dwc3/dwc3-xilinx.c +0 -1
 err_clk_put:
 	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
@@ -315,7 +320,6 @@ static void dwc3_xlnx_remove(struct platform_device *pdev)
 	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks);
 	priv_data->num_clocks = 0;
 
-	pm_runtime_disable(dev);
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);
 }
Signature · 1 line
2.25.1
#2 lore raw
Quoted 27 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, November 11, 2023 5:09 AM
To: Mehta, Piyush <[email protected]>
Cc: [email protected]; Simek, Michal <[email protected]>; Thinh Nguyen <[email protected]>; [email protected]; [email protected]; git (AMD-Xilinx) <[email protected]>
Subject: Re: [PATCH] usb: dwc3: xilinx: improve error handling for PM APIs

Quoted 17 lines · Piyush Mehta

Improve error handling for PM APIs in the dwc3_xlnx_probe function by introducing devm_pm_runtime_enable and error label. Removed unnecessary API pm_runtime_disable call in dwc3_xlnx_remove.

---
 drivers/usb/dwc3/dwc3-xilinx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/dwc3/dwc3-xilinx.c index 5b7e92f476de..9cf26e9a1c3d 100644

drivers/usb/dwc3/dwc3-xilinx.c +0 -0
@@ -294,10 +294,15 @@ static int dwc3_xlnx_probe(struct
 platform_device *pdev)
 
Quoted 6 lines

drivers/usb/dwc3/dwc3-xilinx.c static int dwc3_xlnx_probe(struct platform_device *pdev) · line 297

Quoted 3 lines
drivers/usb/dwc3/dwc3-xilinx.c +1 -0
 	pm_runtime_set_active(dev);
 	pm_runtime_enable(dev);
+	ret = devm_pm_runtime_enable(dev);

You just did pm_runtime_enable() right above, why
devm_pm_runtime_enable() again?

This will fix in next version.

Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/dwc3-xilinx.c +4 -1
+	if (ret < 0)
+		goto err_pm_set_suspended;
+
 	pm_suspend_ignore_children(dev, false);
-	pm_runtime_get_sync(dev);
+	return pm_runtime_resume_and_get(dev);
 
Quoted 5 lines

drivers/usb/dwc3/dwc3-xilinx.c static int dwc3_xlnx_probe(struct platform_device *pdev) · line 305

Quoted 3 lines
drivers/usb/dwc3/dwc3-xilinx.c +2 -1
-	return 0;
+err_pm_set_suspended:
+	pm_runtime_set_suspended(dev);

This doesn't look right. why set status suspended here?

Status is set to suspended in the exit path to undo the state set by pm_runtime_set_active(). The initial runtime PM status of all devices is 'suspended'.

There is a mention of in Documentation/power/runtime_pm.rst
For this reason, once pm_runtime_set_active() has been called for the device, pm_runtime_enable() should be called for it too as soon as reasonably possible or its run-time PM status should be changed back to 'suspended' with the help of pm_runtime_set_suspended().

Quoted 21 lines

BR,
Thinh

drivers/usb/dwc3/dwc3-xilinx.c static void dwc3_xlnx_remove(struct

Quoted 5 lines
drivers/usb/dwc3/dwc3-xilinx.c +0 -0
 err_clk_put:
 	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data-

clks);

drivers/usb/dwc3/dwc3-xilinx.c +0 -0
@@ -315,7 +320,6 @@ static void dwc3_xlnx_remove(struct

platform_device *pdev)

Quoted 11 lines
drivers/usb/dwc3/dwc3-xilinx.c +0 -1
 	clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data-
 clks);
 	priv_data->num_clocks = 0;
 
-	pm_runtime_disable(dev);
 	pm_runtime_put_noidle(dev);
 	pm_runtime_set_suspended(dev);

}
--
2.25.1

maintainer
#3 lore raw

Sorry for the delay response.

Quoted 53 lines · Radhey Shyam
Quoted 27 lines

-----Original Message-----
From: Thinh Nguyen <[email protected]>
Sent: Saturday, November 11, 2023 5:09 AM
To: Mehta, Piyush <[email protected]>
Cc: [email protected]; Simek, Michal <[email protected]>; Thinh Nguyen <[email protected]>; [email protected]; [email protected]; git (AMD-Xilinx) <[email protected]>
Subject: Re: [PATCH] usb: dwc3: xilinx: improve error handling for PM APIs

Quoted 17 lines · Piyush Mehta

Improve error handling for PM APIs in the dwc3_xlnx_probe function by introducing devm_pm_runtime_enable and error label. Removed unnecessary API pm_runtime_disable call in dwc3_xlnx_remove.

---
 drivers/usb/dwc3/dwc3-xilinx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/usb/dwc3/dwc3-xilinx.c index 5b7e92f476de..9cf26e9a1c3d 100644

drivers/usb/dwc3/dwc3-xilinx.c +0 -0
@@ -294,10 +294,15 @@ static int dwc3_xlnx_probe(struct
 platform_device *pdev)
 
Quoted 6 lines

drivers/usb/dwc3/dwc3-xilinx.c static int dwc3_xlnx_probe(struct platform_device *pdev) · line 297

Quoted 3 lines
drivers/usb/dwc3/dwc3-xilinx.c +1 -0
 	pm_runtime_set_active(dev);
 	pm_runtime_enable(dev);
+	ret = devm_pm_runtime_enable(dev);

You just did pm_runtime_enable() right above, why
devm_pm_runtime_enable() again?

This will fix in next version.

Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/dwc3-xilinx.c +4 -1
+	if (ret < 0)
+		goto err_pm_set_suspended;
+
 	pm_suspend_ignore_children(dev, false);
-	pm_runtime_get_sync(dev);
+	return pm_runtime_resume_and_get(dev);
 
Quoted 5 lines

drivers/usb/dwc3/dwc3-xilinx.c static int dwc3_xlnx_probe(struct platform_device *pdev) · line 305

Quoted 3 lines
drivers/usb/dwc3/dwc3-xilinx.c +2 -1
-	return 0;
+err_pm_set_suspended:
+	pm_runtime_set_suspended(dev);

This doesn't look right. why set status suspended here?

Status is set to suspended in the exit path to undo the state set by pm_runtime_set_active(). The initial runtime PM status of all devices is 'suspended'.

Quoted 6 lines

There is a mention of in Documentation/power/runtime_pm.rst
For this reason, once pm_runtime_set_active() has been called for the device, pm_runtime_enable() should be called for it too as soon as reasonably possible or its run-time PM status should be changed back to 'suspended' with the help of pm_runtime_set_suspended().

If your intention of treating the status of devm_pm_runtime_enable() as the status of pm_runtime_enable(), then that's not correct.

BR,
Thinh