Skip to contentSkip to conversation

usb: musb: da8xx: pair OF child population

PATCH New Pengpeng Hou 1 participant 3 messages Aug 13

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

v3 cover usb: musb: da8xx: pair OF child population

da8xx_probe() publishes CPPI child devices with of_platform_populate(). Those children are owned by the DA8xx parent and are not removed by unregistering the separately created MUSB platform device.

The two patches intentionally cover separate lifetime exits. Patch 1 unwinds partially or fully populated children when probe later fails. Patch 2 pairs a successful population during normal driver removal. In both paths, resources are unpublished in the reverse order in which the driver made them visible.

Changes since v2:
https://lore.kernel.org/all/[email protected]/
- split probe-failure cleanup from normal remove cleanup
- document ownership of OF-created children versus the MUSB device
- cover partial failure from of_platform_populate()
- preserve reverse publication order on every exit

The series was reviewed statically against the current tree. I do not have DA8xx hardware for bind/unbind testing.

Pengpeng Hou (2):
usb: musb: da8xx: depopulate OF children on probe failure
usb: musb: da8xx: depopulate OF children on remove

 drivers/usb/musb/da8xx.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

base-commit: f5bbbfec59b4e2fb7520a91de3df8a6174325d6a

Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH v3 1/2 usb: musb: da8xx: depopulate OF children on probe failure

da8xx_probe() creates the CPPI child devices before registering the MUSB platform device. If population partially succeeds or the later MUSB registration fails, the probe path unregisters the generic PHY but leaves the OF children registered under a parent whose probe failed.

Depopulate the OF children before unregistering the PHY on both failure paths. Use one cleanup label so each resource is unwound in reverse publication order without introducing an unused label.

Fixes d6299b6efbf6 ("usb: musb: Add support of CPPI 4.1 DMA controller to DA8xx")
Assisted-by Codex:gpt-5
---
 drivers/usb/musb/da8xx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/musb/da8xx.c +4 -3
index 4209f438ba18..c08ec1241dc0 100644
@@ -562,7 +562,7 @@ static int da8xx_probe(struct platform_device *pdev)
 	ret = of_platform_populate(pdev->dev.of_node, NULL,
 				   da8xx_auxdata_lookup, &pdev->dev);
 	if (ret)
-		goto err_unregister_phy;
+		goto err_depopulate;
 
 	pinfo = da8xx_dev_info;
 	pinfo.parent = &pdev->dev;
@@ -577,12 +577,13 @@ static int da8xx_probe(struct platform_device *pdev)
 	ret = PTR_ERR_OR_ZERO(glue->musb);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register musb device: %d\n", ret);
-		goto err_unregister_phy;
+		goto err_depopulate;
 	}
 
 	return 0;
 
-err_unregister_phy:
+err_depopulate:
+	of_platform_depopulate(&pdev->dev);
 	usb_phy_generic_unregister(glue->usb_phy);
 	return ret;
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

PATCH v3 2/2 usb: musb: da8xx: depopulate OF children on remove

In reply to Pengpeng Hou

da8xx_probe() creates CPPI platform devices with of_platform_populate(), but da8xx_remove() unregisters only the separately created MUSB device and the generic PHY. The OF children therefore remain registered after the glue driver is unbound.

Pair the successful population with of_platform_depopulate() during remove. Unregister the MUSB device first because it reuses the parent DT node but was not created by of_platform_populate().

Fixes d6299b6efbf6 ("usb: musb: Add support of CPPI 4.1 DMA controller to DA8xx")
Assisted-by Codex:gpt-5
---
 drivers/usb/musb/da8xx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/musb/da8xx.c +1 -0
index c08ec1241dc0..6c859a1a11d0 100644
@@ -593,6 +593,7 @@ static void da8xx_remove(struct platform_device *pdev)
 	struct da8xx_glue		*glue = platform_get_drvdata(pdev);
 
 	platform_device_unregister(glue->musb);
+	of_platform_depopulate(&pdev->dev);
 	usb_phy_generic_unregister(glue->usb_phy);
 }
 
Signature · 1 line
2.50.1 (Apple Git-155)