Skip to contentSkip to conversation

usb: musb: mpfs: tidy up error handling in probe()

PATCH In review Felix Gu 2 participants 2 messages Sep 14 – Sep 15

Subsystems (4)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 usb: musb: mpfs: tidy up error handling in probe()

Restructure the probe error labels so each failure only tears down what was already acquired, and stop calling usb_phy_generic_unregister() with NULL or an ERR_PTR() on paths where the phy was never registered.

The old error paths only worked because platform_device_del() and platform_device_put() ignore NULL and ERR_PTR() arguments.

---
 drivers/usb/musb/mpfs.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/usb/musb/mpfs.c +8 -8
index 587127abd30a..59625ed95656 100644
@@ -276,13 +276,13 @@ static int mpfs_probe(struct platform_device *pdev)
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");
 		ret = PTR_ERR(clk);
-		goto err_phy_release;
+		goto err_pdev_put;
 	}
 
 	ret = clk_prepare_enable(clk);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to enable clock\n");
-		goto err_phy_release;
+		goto err_pdev_put;
 	}
 
 	musb_pdev->dev.parent = dev;
@@ -324,29 +324,29 @@ static int mpfs_probe(struct platform_device *pdev)
 	ret = platform_device_add_resources(musb_pdev, pdev->resource, pdev->num_resources);
 	if (ret) {
 		dev_err(dev, "failed to add resources\n");
-		goto err_clk_disable;
+		goto err_phy_release;
 	}
 
 	ret = platform_device_add_data(musb_pdev, pdata, sizeof(*pdata));
 	if (ret) {
 		dev_err(dev, "failed to add platform_data\n");
-		goto err_clk_disable;
+		goto err_phy_release;
 	}
 
 	ret = platform_device_add(musb_pdev);
 	if (ret) {
 		dev_err(dev, "failed to register musb device\n");
-		goto err_clk_disable;
+		goto err_phy_release;
 	}
 
 	dev_info(&pdev->dev, "Registered MPFS MUSB driver\n");
 	return 0;
 
-err_clk_disable:
-	clk_disable_unprepare(clk);
-
 err_phy_release:
 	usb_phy_generic_unregister(glue->phy);
+err_clk_disable:
+	clk_disable_unprepare(clk);
+err_pdev_put:
 	platform_device_put(musb_pdev);
 	return ret;
 }

---
base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
change-id: 20260914-mpfs-1-2e062f29128e

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Felix Gu

Restructure the probe error labels so each failure only tears down what was already acquired, and stop calling usb_phy_generic_unregister() with NULL or an ERR_PTR() on paths where the phy was never registered.

The old error paths only worked because platform_device_del() and platform_device_put() ignore NULL and ERR_PTR() arguments.

---
 drivers/usb/musb/mpfs.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/usb/musb/mpfs.c +0 -0
index 587127abd30a..59625ed95656 100644

drivers/usb/musb/mpfs.c static int mpfs_probe(struct platform_device *pdev) · line 277

Quoted 2 lines
drivers/usb/musb/mpfs.c +0 -0
@@ -276,13 +276,13 @@ static int mpfs_probe(struct platform_device *pdev)
 	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "failed to get clock\n");

Could go a step further if you want, and use devm_clk_get_enabled().

This is clearly the wrong order, so this patch is fine as-is.

Thanks,
Conor.

Quoted 58 lines
drivers/usb/musb/mpfs.c +8 -9
 		ret = PTR_ERR(clk);
-		goto err_phy_release;
+		goto err_pdev_put;
 	}
 
 	ret = clk_prepare_enable(clk);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to enable clock\n");
-		goto err_phy_release;
+		goto err_pdev_put;
 	}
 
 	musb_pdev->dev.parent = dev;
@@ -324,29 +324,29 @@ static int mpfs_probe(struct platform_device *pdev)
 	ret = platform_device_add_resources(musb_pdev, pdev->resource, pdev->num_resources);
 	if (ret) {
 		dev_err(dev, "failed to add resources\n");
-		goto err_clk_disable;
+		goto err_phy_release;
 	}
 
 	ret = platform_device_add_data(musb_pdev, pdata, sizeof(*pdata));
 	if (ret) {
 		dev_err(dev, "failed to add platform_data\n");
-		goto err_clk_disable;
+		goto err_phy_release;
 	}
 
 	ret = platform_device_add(musb_pdev);
 	if (ret) {
 		dev_err(dev, "failed to register musb device\n");
-		goto err_clk_disable;
+		goto err_phy_release;
 	}
 
 	dev_info(&pdev->dev, "Registered MPFS MUSB driver\n");
 	return 0;
 
-err_clk_disable:
-	clk_disable_unprepare(clk);
-
 err_phy_release:
 	usb_phy_generic_unregister(glue->phy);
+err_clk_disable:
+	clk_disable_unprepare(clk);
+err_pdev_put:
 	platform_device_put(musb_pdev);
 	return ret;
 }
 
---

base-commit: 68142f986ff04b2b70b31db00f719bf690f64a9a
change-id: 20260914-mpfs-1-2e062f29128e

Best regards,

Signature · 1 line
Felix Gu <[email protected]>