Re: [PATCH v2] media: i2c: rdacm21: Fix missing media_entity_cleanup()

From: Sakari Ailus

Date: Wed Jul 08 2026 - 11:36:33 EST


Hi Biren,

Thanks for the patches.

On Sun, Jul 05, 2026 at 01:46:28AM +0530, Biren Pandya wrote:
> 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@xxxxxxxxx>
> ---
> 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);

A newline would be nice here.

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

> 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);
> }
>

--
Regards,

Sakari Ailus