Skip to contentSkip to conversation

media: i2c: rdacm21: Fix missing media_entity_cleanup()

PATCH Superseded Biren Pandya 1 participant 1 message Jun 22

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 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.

---
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(-)
drivers/media/i2c/rdacm21.c +4 -1
index bcab462708c7..ece8a410e7ce 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)