Skip to contentSkip to conversation

component: do not try to unbind unbound components

PATCH New Johan Hovold 1 participant 1 message Feb 28, 2025

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

PATCH 1/1 component: do not try to unbind unbound components

Error handling is apparently hard and driver authors often get it wrong.

Continue to warn but do not try to unbind components that have never been bound in order to avoid crashing systems where such a buggy teardown path is hit.

---

I've been sitting on this one for too long now after I ran into such an issue while fixing up the MDM DRM driver which triggered all sorts problems on probe deferral.

Here's a recent example of where a return here would have a avoided a double free:

	https://lore.kernel.org/lkml/6089322f3d5f2e56f4d7a5899d70da2bc45978f7.1702509741.git.soyer@irl.hu/

Arguably, crashing the system is more noticeable, but not very nice for users.

Johan

 drivers/base/component.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/component.c +2 -1
index 741497324d78..3faa92d26be3 100644
@@ -572,7 +572,8 @@ EXPORT_SYMBOL_GPL(component_master_del);
 static void component_unbind(struct component *component,
 	struct aggregate_device *adev, void *data)
 {
-	WARN_ON(!component->bound);
+	if (WARN_ON(!component->bound))
+		return;
 
 	if (component->ops && component->ops->unbind)
 		component->ops->unbind(component->dev, adev->parent, data);
Signature · 1 line
2.45.3