From: Arun Iyengar <[email protected]>

vop2_create_crtcs() returns errors without dropping the port nodes or
the planes and CRTCs it registered. component_bind() then frees struct
vop2 and rockchip_drm_bind() unwinds through drm_mode_config_cleanup()
on the freed planes and CRTCs. The RK3576 interrupt setup after it does
the same.

Call vop2_destroy_crtcs() on these errors and drop every port node
there, not only those of initialised CRTCs.

Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver")
Reported-by: Sashiko <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Arun Iyengar <[email protected]>
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c 
b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
index 76d151b8bc52b..bbe86aecf9039 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
@@ -2757,18 +2757,20 @@ static void vop2_destroy_crtcs(struct vop2 *vop2)
        struct list_head *plane_list = &drm->mode_config.plane_list;
        struct drm_crtc *crtc, *tmpc;
        struct drm_plane *plane, *tmpp;
+       int i;
 
        list_for_each_entry_safe(plane, tmpp, plane_list, head)
                drm_plane_cleanup(plane);
 
+       for (i = 0; i < vop2->data->nr_vps; i++)
+               of_node_put(vop2->vps[i].crtc.port);
+
        /*
         * Destroy CRTC after vop2_plane_destroy() since vop2_disable_plane()
         * references the CRTC.
         */
-       list_for_each_entry_safe(crtc, tmpc, crtc_list, head) {
-               of_node_put(crtc->port);
+       list_for_each_entry_safe(crtc, tmpc, crtc_list, head)
                drm_crtc_cleanup(crtc);
-       }
 }
 
 static int vop2_find_rgb_encoder(struct vop2 *vop2)
@@ -3000,7 +3002,7 @@ static int vop2_bind(struct device *dev, struct device 
*master, void *data)
 
        ret = vop2_create_crtcs(vop2);
        if (ret)
-               return ret;
+               goto err_crtcs;
 
        if (vop2->version >= VOP_VERSION_RK3576) {
                struct drm_crtc *crtc;
@@ -3010,13 +3012,17 @@ static int vop2_bind(struct device *dev, struct device 
*master, void *data)
                        int vp_irq;
                        const char *irq_name = devm_kasprintf(dev, GFP_KERNEL, 
"vp%d", vp->id);
 
-                       if (!irq_name)
-                               return -ENOMEM;
+                       if (!irq_name) {
+                               ret = -ENOMEM;
+                               goto err_crtcs;
+                       }
 
                        vp_irq = platform_get_irq_byname(pdev, irq_name);
-                       if (vp_irq < 0)
-                               return dev_err_probe(drm->dev, vp_irq,
-                                                    "cannot find irq for vop2 
vp%d\n", vp->id);
+                       if (vp_irq < 0) {
+                               ret = dev_err_probe(drm->dev, vp_irq,
+                                                   "cannot find irq for vop2 
vp%d\n", vp->id);
+                               goto err_crtcs;
+                       }
 
                        ret = devm_request_irq(dev, vp_irq, rk3576_vp_isr, 
IRQF_SHARED, irq_name,
                                               vp);

-- 
2.55.0


Reply via email to