Skip to contentSkip to conversation

media: i2c: rdacm21: Fix missing media_entity_cleanup()

PATCH Superseded Biren Pandya 2 participants 2 messages Jun 21 – Jun 22

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: i2c: rdacm21: Fix missing media_entity_cleanup()

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 media_entity_cleanup() to both the error path in rdacm21_probe() and the rdacm21_remove() function to ensure proper resource release.

Fixes a59f853b3b4b ("media: i2c: Add driver for RDACM21 camera module")
---
 drivers/media/i2c/rdacm21.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/rdacm21.c +2 -0
index bcab462708c7..41d4242a9b58 100644
@@ -594,6 +594,7 @@ static int rdacm21_probe(struct i2c_client *client)
 
 error_free_ctrls:
 	v4l2_ctrl_handler_free(&dev->ctrls);
+	media_entity_cleanup(&dev->sd.entity);
 error:
 	i2c_unregister_device(dev->isp);
 
@@ -606,6 +607,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);
 }
 
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

Hi Biren

Quoted 9 lines · Biren Pandya

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 media_entity_cleanup() to both the error path in rdacm21_probe() and the rdacm21_remove() function to ensure proper resource release.

Fixes a59f853b3b4b ("media: i2c: Add driver for RDACM21 camera module")

I wouldn't backport this. media_entity_cleanup() does nothing at the moment and will do nothing on stable kernels as well.

It is anyway worth adding it to the driver in case in future it will do something.

Quoted 10 lines
---
 drivers/media/i2c/rdacm21.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/i2c/rdacm21.c +0 -0
index bcab462708c7..41d4242a9b58 100644

drivers/media/i2c/rdacm21.c static int rdacm21_probe(struct i2c_client *client) · line 597

Quoted 4 lines
drivers/media/i2c/rdacm21.c +1 -0
@@ -594,6 +594,7 @@ static int rdacm21_probe(struct i2c_client *client)
 
 error_free_ctrls:
 	v4l2_ctrl_handler_free(&dev->ctrls);
+	media_entity_cleanup(&dev->sd.entity);

Don't you think a new label befoer error_free_ctrls: (possibile named error_entity_cleanup) would be better ?

The code jumps to error_free_ctrls: even before calling media_entity_pads_init().

Thanks
j

Quoted 14 lines
drivers/media/i2c/rdacm21.c +1 -1
 error:
 	i2c_unregister_device(dev->isp);
 
@@ -606,6 +607,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)