* [PATCH v5 1/4] media: renesas: rcar-csi2: Add missing media_entity_cleanup()
2026-07-08 17:08 [PATCH v5 0/4] media: renesas: Add missing media_entity_cleanup() Biren Pandya
@ 2026-07-08 17:08 ` Biren Pandya
2026-07-08 17:08 ` [PATCH v5 2/4] media: renesas: csisp: " Biren Pandya
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Biren Pandya @ 2026-07-08 17:08 UTC (permalink / raw)
To: niklas.soderlund, mchehab, geert+renesas, magnus.damm,
Laurent Pinchart, Jacopo Mondi, linux-media, linux-renesas-soc,
linux-kernel
Cc: Biren Pandya
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.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
---
drivers/media/platform/renesas/rcar-csi2.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/media/platform/renesas/rcar-csi2.c b/drivers/media/platform/renesas/rcar-csi2.c
index 7305cc4a04cb1..f9c818b0faf7e 100644
--- a/drivers/media/platform/renesas/rcar-csi2.c
+++ b/drivers/media/platform/renesas/rcar-csi2.c
@@ -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);
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v5 2/4] media: renesas: csisp: Add missing media_entity_cleanup()
2026-07-08 17:08 [PATCH v5 0/4] media: renesas: Add missing media_entity_cleanup() Biren Pandya
2026-07-08 17:08 ` [PATCH v5 1/4] media: renesas: rcar-csi2: " Biren Pandya
@ 2026-07-08 17:08 ` Biren Pandya
2026-07-08 17:08 ` [PATCH v5 3/4] media: renesas: rcar-core: " Biren Pandya
2026-07-08 17:08 ` [PATCH v5 4/4] media: renesas: rzg2l-core: " Biren Pandya
3 siblings, 0 replies; 6+ messages in thread
From: Biren Pandya @ 2026-07-08 17:08 UTC (permalink / raw)
To: niklas.soderlund, mchehab, geert+renesas, magnus.damm,
Laurent Pinchart, Jacopo Mondi, linux-media, linux-renesas-soc,
linux-kernel
Cc: Biren Pandya
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.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
---
drivers/media/platform/renesas/rcar-isp/csisp.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/renesas/rcar-isp/csisp.c b/drivers/media/platform/renesas/rcar-isp/csisp.c
index 8fb2cc3b56503..199b70ea841d9 100644
--- a/drivers/media/platform/renesas/rcar-isp/csisp.c
+++ b/drivers/media/platform/renesas/rcar-isp/csisp.c
@@ -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);
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v5 3/4] media: renesas: rcar-core: Add missing media_entity_cleanup()
2026-07-08 17:08 [PATCH v5 0/4] media: renesas: Add missing media_entity_cleanup() Biren Pandya
2026-07-08 17:08 ` [PATCH v5 1/4] media: renesas: rcar-csi2: " Biren Pandya
2026-07-08 17:08 ` [PATCH v5 2/4] media: renesas: csisp: " Biren Pandya
@ 2026-07-08 17:08 ` Biren Pandya
2026-07-08 17:08 ` [PATCH v5 4/4] media: renesas: rzg2l-core: " Biren Pandya
3 siblings, 0 replies; 6+ messages in thread
From: Biren Pandya @ 2026-07-08 17:08 UTC (permalink / raw)
To: niklas.soderlund, mchehab, geert+renesas, magnus.damm,
Laurent Pinchart, Jacopo Mondi, linux-media, linux-renesas-soc,
linux-kernel
Cc: Biren Pandya
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.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
---
drivers/media/platform/renesas/rcar-vin/rcar-core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-core.c b/drivers/media/platform/renesas/rcar-vin/rcar-core.c
index c8d564aa1eba8..5bae8eb0ee19b 100644
--- a/drivers/media/platform/renesas/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/renesas/rcar-vin/rcar-core.c
@@ -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);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v5 4/4] media: renesas: rzg2l-core: Add missing media_entity_cleanup()
2026-07-08 17:08 [PATCH v5 0/4] media: renesas: Add missing media_entity_cleanup() Biren Pandya
` (2 preceding siblings ...)
2026-07-08 17:08 ` [PATCH v5 3/4] media: renesas: rcar-core: " Biren Pandya
@ 2026-07-08 17:08 ` Biren Pandya
2026-07-09 7:05 ` Jacopo Mondi
3 siblings, 1 reply; 6+ messages in thread
From: Biren Pandya @ 2026-07-08 17:08 UTC (permalink / raw)
To: niklas.soderlund, mchehab, geert+renesas, magnus.damm,
Laurent Pinchart, Jacopo Mondi, linux-media, linux-renesas-soc,
linux-kernel
Cc: Biren Pandya
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.
Additionally, patch the error path in rzg2l_cru_media_init() to ensure
that media_device_cleanup(), media_entity_cleanup(), and mutex_destroy()
are invoked and the error code is correctly returned if
rzg2l_cru_mc_parse_of_graph() fails, rather than silently returning 0
and leaving the initialized structures lingering.
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
index 3c5fbd857371c..77b17bcf7aeb7 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
@@ -234,6 +234,10 @@ static int rzg2l_cru_media_init(struct rzg2l_cru_dev *cru)
mutex_lock(&cru->mdev_lock);
cru->v4l2_dev.mdev = NULL;
mutex_unlock(&cru->mdev_lock);
+ media_device_cleanup(mdev);
+ media_entity_cleanup(&cru->vdev.entity);
+ mutex_destroy(&cru->mdev_lock);
+ return ret;
}
return 0;
@@ -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);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v5 4/4] media: renesas: rzg2l-core: Add missing media_entity_cleanup()
2026-07-08 17:08 ` [PATCH v5 4/4] media: renesas: rzg2l-core: " Biren Pandya
@ 2026-07-09 7:05 ` Jacopo Mondi
0 siblings, 0 replies; 6+ messages in thread
From: Jacopo Mondi @ 2026-07-09 7:05 UTC (permalink / raw)
To: Biren Pandya
Cc: niklas.soderlund, mchehab, geert+renesas, magnus.damm,
Laurent Pinchart, Jacopo Mondi, linux-media, linux-renesas-soc,
linux-kernel
Hi Biren
On Wed, Jul 08, 2026 at 10:38:48PM +0530, Biren Pandya wrote:
> 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.
Here and in the other patches, why break the line ?
>
> Add the missing media_entity_cleanup() calls.
>
> Additionally, patch the error path in rzg2l_cru_media_init() to ensure
> that media_device_cleanup(), media_entity_cleanup(), and mutex_destroy()
> are invoked and the error code is correctly returned if
> rzg2l_cru_mc_parse_of_graph() fails, rather than silently returning 0
> and leaving the initialized structures lingering.
>
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> ---
> drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
> index 3c5fbd857371c..77b17bcf7aeb7 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
> @@ -234,6 +234,10 @@ static int rzg2l_cru_media_init(struct rzg2l_cru_dev *cru)
> mutex_lock(&cru->mdev_lock);
> cru->v4l2_dev.mdev = NULL;
> mutex_unlock(&cru->mdev_lock);
> + media_device_cleanup(mdev);
> + media_entity_cleanup(&cru->vdev.entity);
> + mutex_destroy(&cru->mdev_lock);
> + return ret;
Mmmm, this is growing enough to qualify for a label I guess...
Unrelated, but I wonder what
mutex_lock(&cru->mdev_lock);
cru->v4l2_dev.mdev = NULL;
mutex_unlock(&cru->mdev_lock);
Protects against...
What do you think of reworking the error path to make it like
ret = rzg2l_cru_mc_parse_of_graph(cru);
if (ret)
goto err_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;
?
In this case, please reword the commit message accordingly, as the
patch won't just be about adding media_entity_cleanup() but rather
about reworking the rzg2l_cru_media_init() error path.
Thanks
j
> }
>
> return 0;
> @@ -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);
>
> --
> 2.50.1 (Apple Git-155)
>
^ permalink raw reply [flat|nested] 6+ messages in thread