Skip to contentSkip to conversation

drm/msm/mdp4: Fix refcount leak in mdp4_modeset_init_intf

PATCH In review Miaoqian Lin 4 participants 7 messages Jun 7, 2022 – Jun 14, 2022

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

PATCH 1/1 drm/msm/mdp4: Fix refcount leak in mdp4_modeset_init_intf

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")
---
 drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +2 -0
index fb48c8c19ec3..17cb1fc78379 100644
@@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
 		encoder = mdp4_lcdc_encoder_init(dev, panel_node);
 		if (IS_ERR(encoder)) {
 			DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n");
+			of_node_put(panel_node);
 			return PTR_ERR(encoder);
 		}
 
@@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
 		connector = mdp4_lvds_connector_init(dev, panel_node, encoder);
 		if (IS_ERR(connector)) {
 			DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS connector\n");
+			of_node_put(panel_node);
 			return PTR_ERR(connector);
 		}
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Miaoqian Lin

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v1 1/1
#2 lore raw
In reply to Miaoqian Lin

Quoting Miaoqian Lin (2022-06-07 04:08:38)

Quoted 8 lines

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")

---

#3 lore raw
In reply to Miaoqian Lin
Quoted 11 lines · Miaoqian Lin

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")
---
  drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++
  1 file changed, 2 insertions(+)

This patch itself looks fine and will cover the cases when there was an error and we did not release the refcount.

But, even in the normal cases I am not finding where we are releasing the refcount for the panel_node.

I dont see a of_node_put() on mdp4_lcdc_encoder->panel_node.

Am i missing something?

Quoted 20 lines
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +2 -0
index fb48c8c19ec3..17cb1fc78379 100644
@@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
  		encoder = mdp4_lcdc_encoder_init(dev, panel_node);
  		if (IS_ERR(encoder)) {
  			DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n");
+			of_node_put(panel_node);
  			return PTR_ERR(encoder);
  		}
 
@@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
  		connector = mdp4_lvds_connector_init(dev, panel_node, encoder);
  		if (IS_ERR(connector)) {
  			DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS connector\n");
+			of_node_put(panel_node);
  			return PTR_ERR(connector);
  		}
 
#4 lore raw

Hi, Abhinav

Quoted 15 lines · Abhinav Kumar
Quoted 11 lines · Miaoqian Lin

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")

---
  drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++

  1 file changed, 2 insertions(+)
Quoted 6 lines

This patch itself looks fine and will cover the cases when there was an error and we did not release the refcount.

But, even in the normal cases I am not finding where we are releasing the refcount for the panel_node.

I dont see a of_node_put() on mdp4_lcdc_encoder->panel_node.

Thanks for your review.

I don't see it either. It's a bit messy because the reference assigned to mdp4_lcdc_encoder->panel_node and mdp4_lvds_connector->panel_node both.

Quoted 21 lines

Am i missing something?

Quoted 19 lines
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +1 -0
index fb48c8c19ec3..17cb1fc78379 100644
@@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
           encoder = mdp4_lcdc_encoder_init(dev, panel_node);
           if (IS_ERR(encoder)) {
               DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n");
+            of_node_put(panel_node);
               return PTR_ERR(encoder);
           }
   @@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,

          connector = mdp4_lvds_connector_init(dev, panel_node, encoder); if (IS_ERR(connector)) {
              DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS connector\n"); +            of_node_put(panel_node);
              return PTR_ERR(connector);
          }

#5 lore raw
Quoted 20 lines · Miaoqian Lin

Hi, Abhinav

Quoted 17 lines · Abhinav Kumar
Quoted 11 lines · Miaoqian Lin

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")
---
   drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++
   1 file changed, 2 insertions(+)

This patch itself looks fine and will cover the cases when there was an error and we did not release the refcount.

Quoted 7 lines
Quoted 4 lines

But, even in the normal cases I am not finding where we are releasing the refcount for the panel_node.

I dont see a of_node_put() on mdp4_lcdc_encoder->panel_node.

Thanks for your review.

I don't see it either. It's a bit messy because the reference assigned to mdp4_lcdc_encoder->panel_node and mdp4_lvds_connector->panel_node both.

I have a plan to rework mdp4 lcdc support once I get my ifc6410 lvds cable. Thus I think we can land this patch now and fix the mdp4 lcdc/lvds code leaking the reference in the due time.

Quoted 22 lines
Quoted 22 lines

Am i missing something?

Quoted 19 lines
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +1 -0
index fb48c8c19ec3..17cb1fc78379 100644
@@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,
           encoder = mdp4_lcdc_encoder_init(dev, panel_node);
           if (IS_ERR(encoder)) {
               DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n");
+            of_node_put(panel_node);
               return PTR_ERR(encoder);
           }
   @@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms,

          connector = mdp4_lvds_connector_init(dev, panel_node, encoder); if (IS_ERR(connector)) {
              DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS connector\n");
+            of_node_put(panel_node);
              return PTR_ERR(connector);
          }

Signature · 2 lines
With best wishes
Dmitry
Reviewed-by
#6 lore raw
Quoted 23 lines · Dmitry Baryshkov
Quoted 22 lines · Miaoqian Lin

Hi, Abhinav

Quoted 19 lines · Abhinav Kumar
Quoted 11 lines · Miaoqian Lin

of_graph_get_remote_node() returns remote device node pointer with refcount incremented, we should use of_node_put() on it when not need anymore.
Add missing of_node_put() to avoid refcount leak.

Fixes 86418f90a4c1 ("drm: convert drivers to use of_graph_get_remote_node")

---
   drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c | 2 ++

   1 file changed, 2 insertions(+)

This patch itself looks fine and will cover the cases when there was an error and we did not release the refcount.

But, even in the normal cases I am not finding where we are releasing the refcount for the panel_node.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I dont see a of_node_put() on mdp4_lcdc_encoder->panel_node.

Thanks for your review.

I don't see it either. It's a bit messy because the reference assigned to mdp4_lcdc_encoder->panel_node and mdp4_lvds_connector->panel_node both.

I have a plan to rework mdp4 lcdc support once I get my ifc6410 lvds cable. Thus I think we can land this patch now and fix the mdp4 lcdc/lvds code leaking the reference in the due time.

Alright, with that assurance,

Will pick it up for -fixes.

Quoted 24 lines
Quoted 22 lines
Quoted 22 lines

Am i missing something?

Quoted 19 lines
drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.c +1 -0
index fb48c8c19ec3..17cb1fc78379 100644
@@ -216,6 +216,7 @@ static int mdp4_modeset_init_intf(struct 
 mdp4_kms *mdp4_kms,
            encoder = mdp4_lcdc_encoder_init(dev, panel_node);
            if (IS_ERR(encoder)) {
                DRM_DEV_ERROR(dev->dev, "failed to construct LCDC encoder\n");
+            of_node_put(panel_node);
                return PTR_ERR(encoder);
            }

   @@ -225,6 +226,7 @@ static int mdp4_modeset_init_intf(struct mdp4_kms *mdp4_kms, connector = mdp4_lvds_connector_init(dev, panel_node, encoder); if (IS_ERR(connector)) {
               DRM_DEV_ERROR(dev->dev, "failed to initialize LVDS connector\n"); +            of_node_put(panel_node);
               return PTR_ERR(connector);
           }