[PATCH v3] media: platform: mtk-mdp3: Fix resource leak in mdp_get_subsys_id() and mdp_comp_config()

Lu Hongfei luhongfei at vivo.com
Mon Jun 12 20:27:27 PDT 2023


Add a put_device() call for the release of the object
which was determined by a of_find_device_by_node() call
in mdp_get_subsys_id().

Add of_node_put() call for the release of the object
which was determined by a for_each_child_of_node() call
in mdp_comp_config().

Signed-off-by: Lu Hongfei <luhongfei at vivo.com>
---
The previous version’s Subject was:
[PATCH v2] media: platform: mtk-mdp3: Fix resource leaks in mdp_get_subsys_id()

The modifications made compared to the previous version are as follows:
1. Modified the patch subject
2. Fix resource leak issue in mdp_comp_config()

 drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
index a605e80c7dc3..85c5f89f2ed2
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c
@@ -892,13 +892,16 @@ static int mdp_get_subsys_id(struct mdp_dev *mdp, struct device *dev,
 	ret = cmdq_dev_get_client_reg(&comp_pdev->dev, &cmdq_reg, index);
 	if (ret != 0) {
 		dev_err(&comp_pdev->dev, "cmdq_dev_get_subsys fail!\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_device;
 	}
 
 	comp->subsys_id = cmdq_reg.subsys;
 	dev_dbg(&comp_pdev->dev, "subsys id=%d\n", cmdq_reg.subsys);
 
-	return 0;
+put_device:
+	put_device(&comp_pdev->dev);
+	return ret;
 }
 
 static void __mdp_comp_init(struct mdp_dev *mdp, struct device_node *node,
@@ -1135,6 +1138,7 @@ int mdp_comp_config(struct mdp_dev *mdp)
 		comp = mdp_comp_create(mdp, node, id);
 		if (IS_ERR(comp)) {
 			ret = PTR_ERR(comp);
+			of_node_put(node);
 			goto err_init_comps;
 		}
 
@@ -1144,6 +1148,8 @@ int mdp_comp_config(struct mdp_dev *mdp)
 		pm_runtime_enable(comp->comp_dev);
 	}
 
+	of_node_put(node);
+
 	ret = mdp_comp_sub_create(mdp);
 	if (ret)
 		goto err_init_comps;
-- 
2.39.0




More information about the Linux-mediatek mailing list