Skip to contentSkip to conversation

media: i2c: rdacm21: Fix missing media_entity_cleanup()

PATCH Superseded Biren Pandya 2 participants 5 messages Jul 4 – Jul 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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

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")

---
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(-)
drivers/media/i2c/rdacm21.c +4 -1
index bcab462708c70..ece8a410e7ced 100644
@@ -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);
 }
 
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

Hi Biren,

Thanks for the patches.

Quoted 22 lines · 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")

---
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(-)
drivers/media/i2c/rdacm21.c +0 -0
index bcab462708c70..ece8a410e7ced 100644

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

Quoted 10 lines
drivers/media/i2c/rdacm21.c +3 -1
@@ -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);

A newline would be nice here.

Somehow the patch can't be found in linuxtv.org...

Quoted 11 lines
drivers/media/i2c/rdacm21.c +1 -0
 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);
 }
 
Signature · 3 lines
Regards,

Sakari Ailus
#2 lore raw

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

In reply to 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 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.

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

---
Changes in v3:
- Added a blank line after media_entity_cleanup() in the error path (Sakari).

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, 3 insertions(+), 2 deletions(-)
drivers/media/i2c/rdacm21.c +3 -2
index 41d4242a9b583..ece8a410e7ced 100644
@@ -588,13 +588,14 @@ 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);
-	media_entity_cleanup(&dev->sd.entity);
 error:
 	i2c_unregister_device(dev->isp);
 
Signature · 1 line
2.50.1 (Apple Git-155)
#3 lore raw

PATCH v3 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 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.

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

---
Changes in v3:
- Added a blank line after media_entity_cleanup() in the error path (Sakari).

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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/i2c/rdacm21.c +4 -2
index 41d4242a9b583..5cf159eb8891c 100644
@@ -588,13 +588,15 @@ 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);
-	media_entity_cleanup(&dev->sd.entity);
 error:
 	i2c_unregister_device(dev->isp);
 
Signature · 1 line
2.50.1 (Apple Git-155)
#4 lore raw

PATCH v4 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 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.

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

---
Changes in v4:
- Rebased onto latest linux-media next branch to resolve a merge conflict in rdacm21.c (as reported by Media CI).

Changes in v3:
- Added a blank line after media_entity_cleanup() in the error path (Sakari).

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(-)
drivers/media/i2c/rdacm21.c +4 -1
index bcab462708c70..531b71d0a94df 100644
@@ -588,10 +588,13 @@ 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:
Signature · 1 line
2.50.1 (Apple Git-155)