Skip to contentSkip to conversation

drm/mediatek: ovl_adaptor: balance component registrations

PATCH In review Myeonghun Pak 2 participants 2 messages Jul 21 – Jul 28

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

PATCH 1/1 drm/mediatek: ovl_adaptor: balance component registrations

The OVL adaptor registers both an aggregate driver for its child devices and a component for the main DRM aggregate. Probe currently ignores an error from registering the child aggregate and leaves that aggregate registered if registering the DRM component fails. The remove callback also leaves the DRM component registered.

These imbalances can leave component framework entries referring to a device whose probe failed or whose driver has been detached. The aggregate unbind callback also fails to undo component_bind_all(), leaving its child components marked as bound when the aggregate is removed.

Check the aggregate registration result, unwind it when the component registration fails, and unregister the component before the aggregate on remove. Keep runtime PM enabled until both framework registrations have been removed, and unbind all child components from the aggregate unbind callback.

Fixes 453c3364632a ("drm/mediatek: Add ovl_adaptor support for MT8195")
---
 drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +6 -1
index c0af3e3b5..6a259872b 100644
@@ -625,6 +625,7 @@ static void mtk_disp_ovl_adaptor_master_unbind(struct device *dev)
 	struct mtk_disp_ovl_adaptor *priv = dev_get_drvdata(dev);
 
 	priv->children_bound = false;
+	component_unbind_all(dev, priv->mmsys_dev);
 }
 
 static const struct component_master_ops mtk_disp_ovl_adaptor_master_ops = {
@@ -651,12 +652,15 @@ static int mtk_disp_ovl_adaptor_probe(struct platform_device *pdev)
 
 	priv->mmsys_dev = pdev->dev.platform_data;
 
-	component_master_add_with_match(dev, &mtk_disp_ovl_adaptor_master_ops, match);
+	ret = component_master_add_with_match(dev, &mtk_disp_ovl_adaptor_master_ops, match);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to add component master\n");
 
 	pm_runtime_enable(dev);
 
 	ret = component_add(dev, &mtk_disp_ovl_adaptor_comp_ops);
 	if (ret != 0) {
+		component_master_del(dev, &mtk_disp_ovl_adaptor_master_ops);
 		pm_runtime_disable(dev);
 		return dev_err_probe(dev, ret, "Failed to add component\n");
 	}
@@ -666,6 +670,7 @@ static int mtk_disp_ovl_adaptor_probe(struct platform_device *pdev)
 
 static void mtk_disp_ovl_adaptor_remove(struct platform_device *pdev)
 {
+	component_del(&pdev->dev, &mtk_disp_ovl_adaptor_comp_ops);
 	component_master_del(&pdev->dev, &mtk_disp_ovl_adaptor_master_ops);
 	pm_runtime_disable(&pdev->dev);
 }
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Myeonghun Pak

External email : Please do not click links or open attachments until you have verified the sender or the content.

The OVL adaptor registers both an aggregate driver for its child devices and a component for the main DRM aggregate. Probe currently ignores an error from registering the child aggregate and leaves that aggregate registered if registering the DRM component fails. The remove callback also leaves the DRM component registered.

These imbalances can leave component framework entries referring to a device whose probe failed or whose driver has been detached. The aggregate unbind callback also fails to undo component_bind_all(), leaving its child components marked as bound when the aggregate is removed.

Quoted 5 lines

Check the aggregate registration result, unwind it when the component registration fails, and unregister the component before the aggregate on remove. Keep runtime PM enabled until both framework registrations have been removed, and unbind all child components from the aggregate unbind callback.

Quoted 49 lines
Fixes 453c3364632a ("drm/mediatek: Add ovl_adaptor support for MT8195")
---
 drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +6 -2
index c0af3e3b5..6a259872b 100644
@@ -625,6 +625,7 @@ static void mtk_disp_ovl_adaptor_master_unbind(struct device *dev)
        struct mtk_disp_ovl_adaptor *priv = dev_get_drvdata(dev);
 
        priv->children_bound = false;
+       component_unbind_all(dev, priv->mmsys_dev);
 }
 
 static const struct component_master_ops mtk_disp_ovl_adaptor_master_ops = {
@@ -651,12 +652,15 @@ static int mtk_disp_ovl_adaptor_probe(struct platform_device *pdev)
 
        priv->mmsys_dev = pdev->dev.platform_data;
 
-       component_master_add_with_match(dev, &mtk_disp_ovl_adaptor_master_ops, match);
+       ret = component_master_add_with_match(dev, &mtk_disp_ovl_adaptor_master_ops, match);
+       if (ret)
+               return dev_err_probe(dev, ret, "Failed to add component master\n");
 
        pm_runtime_enable(dev);
 
        ret = component_add(dev, &mtk_disp_ovl_adaptor_comp_ops);
        if (ret != 0) {
+               component_master_del(dev, &mtk_disp_ovl_adaptor_master_ops);
                pm_runtime_disable(dev);
                return dev_err_probe(dev, ret, "Failed to add component\n");
        }
@@ -666,6 +670,7 @@ static int mtk_disp_ovl_adaptor_probe(struct platform_device *pdev)
 
 static void mtk_disp_ovl_adaptor_remove(struct platform_device *pdev)
 {
+       component_del(&pdev->dev, &mtk_disp_ovl_adaptor_comp_ops);
        component_master_del(&pdev->dev, &mtk_disp_ovl_adaptor_master_ops);
        pm_runtime_disable(&pdev->dev);
 }
--

2.51.0