Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH v2] media: i2c: rdacm21: Fix missing media_entity_cleanup()
@ 2026-07-04 20:16 Biren Pandya
  2026-07-08 15:04 ` Sakari Ailus
  2026-07-08 15:29 ` [PATCH v3] " Biren Pandya
  0 siblings, 2 replies; 6+ messages in thread
From: Biren Pandya @ 2026-07-04 20:16 UTC (permalink / raw)
  To: Jacopo Mondi, Kieran Bingham, Laurent Pinchart,
	Niklas Söderlund, Mauro Carvalho Chehab
  Cc: Sakari Ailus, linux-media, linux-kernel, Biren Pandya

The driver misses calling media_entity_cleanup() on the probe error path
and during remove, leaking resources if probe fails after entity
initialization or when the driver is unloaded.

Fix this by adding media_entity_cleanup() to the rdacm21_probe() error
handling path and to rdacm21_remove().

Fixes: a59f853b3b4b ("media: i2c: Add driver for RDACM21 camera module")
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
Changes in v2:
- Fixed a bug in v1's probe error handling where media_entity_cleanup() could be called on an uninitialized entity.
- Added Signed-off-by tag which was missing in v1.

 drivers/media/i2c/rdacm21.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
index bcab462708c70..ece8a410e7ced 100644
--- a/drivers/media/i2c/rdacm21.c
+++ b/drivers/media/i2c/rdacm21.c
@@ -588,10 +588,12 @@ static int rdacm21_probe(struct i2c_client *client)
 
 	ret = v4l2_async_register_subdev(&dev->sd);
 	if (ret)
-		goto error_free_ctrls;
+		goto error_entity_cleanup;
 
 	return 0;
 
+error_entity_cleanup:
+	media_entity_cleanup(&dev->sd.entity);
 error_free_ctrls:
 	v4l2_ctrl_handler_free(&dev->ctrls);
 error:
@@ -606,6 +608,7 @@ static void rdacm21_remove(struct i2c_client *client)
 
 	v4l2_async_unregister_subdev(&dev->sd);
 	v4l2_ctrl_handler_free(&dev->ctrls);
+	media_entity_cleanup(&dev->sd.entity);
 	i2c_unregister_device(dev->isp);
 }
 
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH v3] media: i2c: rdacm21: Fix missing media_entity_cleanup()
@ 2026-06-22 17:47 Biren Pandya
  0 siblings, 0 replies; 6+ messages in thread
From: Biren Pandya @ 2026-06-22 17:47 UTC (permalink / raw)
  To: linux-media
  Cc: jacopo.mondi, laurent.pinchart, kieran.bingham+renesas, mchehab,
	sakari.ailus, linux-renesas-soc, linux-kernel, Biren Pandya,
	Jacopo Mondi, Laurent Pinchart, Niklas Söderlund

If an error occurs after media_entity_pads_init() is called, the media
entity is left uncleaned, potentially leaking resources or leaving it
in an invalid state. Similarly, the remove path misses the cleanup.

Add a dedicated error_entity_cleanup label so that media_entity_cleanup()
is only invoked on the error path when media_entity_pads_init() has
actually succeeded. Also add media_entity_cleanup() to rdacm21_remove()
to ensure proper resource release on driver unload.

Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
Changes in v3:
- Added a dedicated error_entity_cleanup label so the cleanup is
  only called if pads initialization succeeds (per Jacopo Mondi).
- Removed Cc stable tag.

 drivers/media/i2c/rdacm21.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
index bcab462708c7..ece8a410e7ce 100644
--- a/drivers/media/i2c/rdacm21.c
+++ b/drivers/media/i2c/rdacm21.c
@@ -588,10 +588,12 @@ static int rdacm21_probe(struct i2c_client *client)
 
 	ret = v4l2_async_register_subdev(&dev->sd);
 	if (ret)
-		goto error_free_ctrls;
+		goto error_entity_cleanup;
 
 	return 0;
 
+error_entity_cleanup:
+	media_entity_cleanup(&dev->sd.entity);
 error_free_ctrls:
 	v4l2_ctrl_handler_free(&dev->ctrls);
 error:
@@ -606,6 +608,7 @@ static void rdacm21_remove(struct i2c_client *client)
 
 	v4l2_async_unregister_subdev(&dev->sd);
 	v4l2_ctrl_handler_free(&dev->ctrls);
+	media_entity_cleanup(&dev->sd.entity);
 	i2c_unregister_device(dev->isp);
 }
 
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-08 15:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-04 20:16 [PATCH v2] media: i2c: rdacm21: Fix missing media_entity_cleanup() Biren Pandya
2026-07-08 15:04 ` Sakari Ailus
2026-07-08 15:29 ` [PATCH v3] " Biren Pandya
2026-07-08 15:44   ` Biren Pandya
2026-07-08 15:44     ` [PATCH v4] " Biren Pandya
  -- strict thread matches above, loose matches on Subject: below --
2026-06-22 17:47 [PATCH v3] " Biren Pandya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox