Skip to contentSkip to conversation

media: renesas: rcar-csi2: Add missing media_entity_cleanup()

PATCH New Biren Pandya 1 participant 4 messages Jul 9 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v6 1/4 media: renesas: rcar-csi2: Add missing media_entity_cleanup()

The probe error paths and the remove function fail to call media_entity_cleanup() upon teardown.

While currently a no-op, calling media_entity_cleanup() is an API requirement for entities initialized with media_entity_pads_init() to prevent memory leaks.

Add the missing media_entity_cleanup() calls.

---
 drivers/media/platform/renesas/rcar-csi2.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/renesas/rcar-csi2.c +2 -0
index 7305cc4a04cb1..f9c818b0faf7e 100644
@@ -2631,6 +2631,7 @@ static int rcsi2_probe(struct platform_device *pdev)
 	v4l2_subdev_cleanup(&priv->subdev);
 error_pm_runtime:
 	pm_runtime_disable(&pdev->dev);
+	media_entity_cleanup(&priv->subdev.entity);
 error_async:
 	v4l2_async_nf_unregister(&priv->notifier);
 	v4l2_async_nf_cleanup(&priv->notifier);
@@ -2646,6 +2647,7 @@ static void rcsi2_remove(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&priv->notifier);
 	v4l2_async_unregister_subdev(&priv->subdev);
 	v4l2_subdev_cleanup(&priv->subdev);
+	media_entity_cleanup(&priv->subdev.entity);
 
 	pm_runtime_disable(&pdev->dev);
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

PATCH v6 2/4 media: renesas: csisp: Add missing media_entity_cleanup()

In reply to a message not in the archive

The probe error path and remove function fail to call media_entity_cleanup() upon teardown.

While currently a no-op, calling media_entity_cleanup() is an API requirement for entities initialized with media_entity_pads_init() to prevent memory leaks.

Add a dedicated error_entity label so the cleanup is only invoked when media_entity_pads_init() has actually succeeded. This ensures that the teardown logic properly mirrors initialization.

---
 drivers/media/platform/renesas/rcar-isp/csisp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/renesas/rcar-isp/csisp.c +5 -1
index 8fb2cc3b56503..199b70ea841d9 100644
@@ -539,7 +539,7 @@ static int risp_probe(struct platform_device *pdev)
 
 	ret = v4l2_subdev_init_finalize(&isp->subdev);
 	if (ret)
-		goto error_notifier;
+		goto error_entity;
 
 	ret = v4l2_async_register_subdev(&isp->subdev);
 	if (ret < 0)
@@ -551,6 +551,9 @@ static int risp_probe(struct platform_device *pdev)
 
 error_subdev:
 	v4l2_subdev_cleanup(&isp->subdev);
+error_entity:
+	media_entity_cleanup(&isp->subdev.entity);
+
 error_notifier:
 	v4l2_async_nf_unregister(&isp->notifier);
 	v4l2_async_nf_cleanup(&isp->notifier);
@@ -569,6 +572,7 @@ static void risp_remove(struct platform_device *pdev)
 
 	v4l2_async_unregister_subdev(&isp->subdev);
 	v4l2_subdev_cleanup(&isp->subdev);
+	media_entity_cleanup(&isp->subdev.entity);
 
 	pm_runtime_disable(&pdev->dev);
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#3 lore raw

PATCH v6 3/4 media: renesas: rcar-core: Add missing media_entity_cleanup()

In reply to a message not in the archive

The probe error path and remove function fail to call media_entity_cleanup() upon teardown.

While currently a no-op, calling media_entity_cleanup() is an API requirement for entities initialized with media_entity_pads_init() to prevent memory leaks.

Add a dedicated error_entity label so the cleanup is only invoked when media_entity_pads_init() has actually succeeded. This ensures that the teardown logic properly mirrors initialization.

---
 drivers/media/platform/renesas/rcar-vin/rcar-core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/renesas/rcar-vin/rcar-core.c +4 -1
index c8d564aa1eba8..5bae8eb0ee19b 100644
@@ -1211,7 +1211,7 @@ static int rcar_vin_probe(struct platform_device *pdev)
 
 	ret = rvin_create_controls(vin);
 	if (ret < 0)
-		goto err_id;
+		goto err_entity;
 
 	switch (vin->info->model) {
 	case RCAR_GEN3:
@@ -1246,6 +1246,8 @@ static int rcar_vin_probe(struct platform_device *pdev)
 
 err_ctrl:
 	rvin_free_controls(vin);
+err_entity:
+	media_entity_cleanup(&vin->vdev.entity);
 err_id:
 	rvin_id_put(vin);
 err_dma:
@@ -1270,6 +1272,7 @@ static void rcar_vin_remove(struct platform_device *pdev)
 	rvin_group_put(vin);
 
 	rvin_free_controls(vin);
+	media_entity_cleanup(&vin->vdev.entity);
 
 	rvin_id_put(vin);
 
Signature · 1 line
2.50.1 (Apple Git-155)
#4 lore raw

PATCH v6 4/4 media: renesas: rzg2l-core: Add missing media_entity_cleanup()

In reply to a message not in the archive

The media initialization error path and the remove function fail to call media_entity_cleanup() upon teardown.

While currently a no-op, calling media_entity_cleanup() is an API requirement for entities initialized with media_entity_pads_init() to prevent memory leaks.

Add the missing media_entity_cleanup() calls.

Additionally, rework the error path in rzg2l_cru_media_init() to use an error_mc_parse label, ensuring that cleanup functions are invoked and the unnecessary mutex lock is removed.

---
 .../media/platform/renesas/rzg2l-cru/rzg2l-core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +10 -5
index 3c5fbd857371c..ee555b01c3aa1 100644
@@ -230,13 +230,17 @@ static int rzg2l_cru_media_init(struct rzg2l_cru_dev *cru)
 	media_device_init(mdev);
 
 	ret = rzg2l_cru_mc_parse_of_graph(cru);
-	if (ret) {
-		mutex_lock(&cru->mdev_lock);
-		cru->v4l2_dev.mdev = NULL;
-		mutex_unlock(&cru->mdev_lock);
-	}
+	if (ret)
+		goto error_mc_parse;
 
 	return 0;
+
+error_mc_parse:
+	media_device_cleanup(mdev);
+	cru->v4l2_dev.mdev = NULL;
+	media_entity_cleanup(&cru->vdev.entity);
+	mutex_destroy(&cru->mdev_lock);
+	return ret;
 }
 
 static int rzg2l_cru_probe(struct platform_device *pdev)
@@ -312,6 +316,7 @@ static void rzg2l_cru_remove(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&cru->notifier);
 
 	rzg2l_cru_video_unregister(cru);
+	media_entity_cleanup(&cru->vdev.entity);
 	media_device_cleanup(&cru->mdev);
 	mutex_destroy(&cru->mdev_lock);
 
Signature · 1 line
2.50.1 (Apple Git-155)