media: renesas: Add missing media_entity_cleanup()
Subsystems (4)
v5 cover media: renesas: Add missing media_entity_cleanup()
This patch series addresses missing media_entity_cleanup() calls across multiple Renesas platform drivers (rcar-csi2, csisp, rcar-vin, and rzg2l-cru).
While media_entity_cleanup() is currently a no-op when CONFIG_MEDIA_CONTROLLER is disabled (and even when enabled in modern kernels, as pads are rarely dynamically allocated anymore), the media subsystem guidelines strictly require drivers to call it to prevent future leaks if the core framework behavior changes.
Changes in v5:
- Removed "in most cases" from all commit messages per Jacopo's review.
- Fixed missing empty line before Signed-off-by across the series.
- Patched the error path in rzg2l_cru_media_init() to properly cleanup resources on failure per Jacopo's suggestion.
- Collected Reviewed-by tags from Jacopo Mondi for patches 1/4, 2/4, and 3/4.
Changes in v4:
- Formatted commit messages to strictly adhere to the 75-character limit per line to resolve checkpatch warnings on the mailing list.
- Removed unwrapped long lines from the commit descriptions.
Changes in v3:
- Addressed maintainer feedback from Jacopo Mondi to fix an unused-label compilation error in rcar-csi2.c. The teardown inversion is now handled cleanly inside the existing error path without requiring a new label.
Changes in v2:
- Introduced dedicated error labels in probe paths where shared error labels previously caused media_entity_cleanup() to be skipped or improperly called.
Biren Pandya (4):
media: renesas: rcar-csi2: Add missing media_entity_cleanup()
media: renesas: csisp: Add missing media_entity_cleanup()
media: renesas: rcar-core: Add missing media_entity_cleanup()
media: renesas: rzg2l-core: Add missing media_entity_cleanup()
drivers/media/platform/renesas/rcar-csi2.c | 2 ++ drivers/media/platform/renesas/rcar-isp/csisp.c | 6 +++++- drivers/media/platform/renesas/rcar-vin/rcar-core.c | 5 ++++- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 5 +++++ 4 files changed, 16 insertions(+), 2 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v5 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
@@ -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)
PATCH v5 2/4 media: renesas: csisp: Add missing media_entity_cleanup()
In reply to Biren PandyaThe 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
@@ -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)
PATCH v5 3/4 media: renesas: rcar-core: Add missing media_entity_cleanup()
In reply to Biren PandyaThe 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
@@ -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)
PATCH v5 4/4 media: renesas: rzg2l-core: Add missing media_entity_cleanup()
In reply to Biren PandyaThe 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.
--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +5 -0
@@ -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);
Signature · 1 line
2.50.1 (Apple Git-155)
Jacopo Mondi
maintainerRe: [PATCH v5 4/4] media: renesas: rzg2l-core: Add missing media_entity_cleanup()
Hi Biren
Quoted 7 lines · 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 withmedia_entity_pads_init()
to prevent memory leaks.
Here and in the other patches, why break the line ?
Quoted 19 lines
Add the missing
media_entity_cleanup()calls.Additionally, patch the error path in
rzg2l_cru_media_init()to ensure thatmedia_device_cleanup(),media_entity_cleanup(), andmutex_destroy()are invoked and the error code is correctly returned ifrzg2l_cru_mc_parse_of_graph()fails, rather than silently returning 0 and leaving the initialized structures lingering.Signed-off-by Biren Pandya <[email protected]>--- drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +0
-0
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c static int rzg2l_cru_media_init(struct rzg2l_cru_dev *cru) · line 240
Quoted 7 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +4
-0@@ -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
Quoted 14 lines
drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c +1
-1}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)