Skip to contentSkip to conversation

media: platform: Fix refcount leak in probe and remove function

PATCH In review Miaoqian Lin 2 participants 2 messages Jan 6, 2023

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

PATCH 1/1 media: platform: Fix refcount leak in probe and remove function

rcar_fcp_get() take reference, which should be balanced with rcar_fcp_put(). Add missing rcar_fcp_put() in fdp1_remove and the error paths of fdp1_probe() to fix this.

Fixes 4710b752e029 ("[media] v4l: Add Renesas R-Car FDP1 Driver")

---
I take commit Fixes: 7113469dafc2 ("media: vsp1: Fix an error handling path in the probe function") for reference.

---
 drivers/media/platform/renesas/rcar_fdp1.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/renesas/rcar_fdp1.c +8 -3
index 37ecf489d112..ed97bb161743 100644
@@ -2313,8 +2313,10 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	/* Determine our clock rate */
 	clk = clk_get(&pdev->dev, NULL);
-	if (IS_ERR(clk))
-		return PTR_ERR(clk);
+	if (IS_ERR(clk)) {
+		ret = PTR_ERR(clk);
+		goto put_dev;
+	}
 
 	fdp1->clk_rate = clk_get_rate(clk);
 	clk_put(clk);
@@ -2323,7 +2325,7 @@ static int fdp1_probe(struct platform_device *pdev)
 	ret = v4l2_device_register(&pdev->dev, &fdp1->v4l2_dev);
 	if (ret) {
 		v4l2_err(&fdp1->v4l2_dev, "Failed to register video device\n");
-		return ret;
+		goto put_dev;
 	}
 
 	/* M2M registration */
@@ -2393,6 +2395,8 @@ static int fdp1_probe(struct platform_device *pdev)
 unreg_dev:
 	v4l2_device_unregister(&fdp1->v4l2_dev);
 
+put_dev:
+	rcar_fcp_put(fdp1->fcp);
 	return ret;
 }
 
@@ -2400,6 +2404,7 @@ static int fdp1_remove(struct platform_device *pdev)
 {
 	struct fdp1_dev *fdp1 = platform_get_drvdata(pdev);
 
+	rcar_fcp_put(fdp1->fcp);
 	v4l2_m2m_release(fdp1->m2m_dev);
 	video_unregister_device(&fdp1->vfd);
 	v4l2_device_unregister(&fdp1->v4l2_dev);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Hello Miaoqian,

Thank you for the patch.

Quoted 49 lines · Miaoqian Lin

rcar_fcp_get() take reference, which should be balanced with rcar_fcp_put(). Add missing rcar_fcp_put() in fdp1_remove and the error paths of fdp1_probe() to fix this.

Fixes 4710b752e029 ("[media] v4l: Add Renesas R-Car FDP1 Driver")

---
I take commit Fixes: 7113469dafc2 ("media: vsp1: Fix an error handling path in the probe function") for reference.

---
 drivers/media/platform/renesas/rcar_fdp1.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/renesas/rcar_fdp1.c +7 -3
index 37ecf489d112..ed97bb161743 100644
@@ -2313,8 +2313,10 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	/* Determine our clock rate */
 	clk = clk_get(&pdev->dev, NULL);
-	if (IS_ERR(clk))
-		return PTR_ERR(clk);
+	if (IS_ERR(clk)) {
+		ret = PTR_ERR(clk);
+		goto put_dev;
+	}
 
 	fdp1->clk_rate = clk_get_rate(clk);
 	clk_put(clk);
@@ -2323,7 +2325,7 @@ static int fdp1_probe(struct platform_device *pdev)
 	ret = v4l2_device_register(&pdev->dev, &fdp1->v4l2_dev);
 	if (ret) {
 		v4l2_err(&fdp1->v4l2_dev, "Failed to register video device\n");
-		return ret;
+		goto put_dev;
 	}
 
 	/* M2M registration */
@@ -2393,6 +2395,8 @@ static int fdp1_probe(struct platform_device *pdev)
 unreg_dev:
 	v4l2_device_unregister(&fdp1->v4l2_dev);
 
+put_dev:
+	rcar_fcp_put(fdp1->fcp);
 	return ret;
 }
 

drivers/media/platform/renesas/rcar_fdp1.c static int fdp1_remove(struct platform_device *pdev) · line 2407

Quoted 4 lines
drivers/media/platform/renesas/rcar_fdp1.c +1 -0
@@ -2400,6 +2404,7 @@ static int fdp1_remove(struct platform_device *pdev)
 {
 	struct fdp1_dev *fdp1 = platform_get_drvdata(pdev);
 
+	rcar_fcp_put(fdp1->fcp);

I would move it at the end, after unregistering the V4L2 device, as here we may still be using the fcp.

Apart from that, the patch looks good to me.

No need to send a v2, I'll make this small change in my tree.

Quoted 3 lines
drivers/media/platform/renesas/rcar_fdp1.c +0 -0
 	v4l2_m2m_release(fdp1->m2m_dev);
 	video_unregister_device(&fdp1->vfd);
 	v4l2_device_unregister(&fdp1->v4l2_dev);
Signature · 3 lines
Regards,

Laurent Pinchart