* [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; 7+ 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 [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: i2c: rdacm21: Fix missing media_entity_cleanup()
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
1 sibling, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2026-07-08 15:04 UTC (permalink / raw)
To: Biren Pandya
Cc: Jacopo Mondi, Kieran Bingham, Laurent Pinchart,
Niklas Söderlund, Mauro Carvalho Chehab, linux-media,
linux-kernel
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@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);
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] media: i2c: rdacm21: Fix missing media_entity_cleanup()
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 ` Biren Pandya
2026-07-08 15:44 ` Biren Pandya
1 sibling, 1 reply; 7+ messages in thread
From: Biren Pandya @ 2026-07-08 15:29 UTC (permalink / raw)
To: jacopo+renesas, kieran.bingham+renesas, laurent.pinchart+renesas,
Niklas Söderlund, mchehab, sakari.ailus, linux-media,
linux-kernel
Cc: 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")
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
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(-)
diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
index 41d4242a9b583..ece8a410e7ced 100644
--- a/drivers/media/i2c/rdacm21.c
+++ b/drivers/media/i2c/rdacm21.c
@@ -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);
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] media: i2c: rdacm21: Fix missing media_entity_cleanup()
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
0 siblings, 1 reply; 7+ messages in thread
From: Biren Pandya @ 2026-07-08 15:44 UTC (permalink / raw)
To: jacopo+renesas, kieran.bingham+renesas, laurent.pinchart+renesas,
Niklas Söderlund, mchehab, sakari.ailus, linux-media,
linux-kernel
Cc: 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")
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
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(-)
diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
index 41d4242a9b583..5cf159eb8891c 100644
--- a/drivers/media/i2c/rdacm21.c
+++ b/drivers/media/i2c/rdacm21.c
@@ -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);
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4] media: i2c: rdacm21: Fix missing media_entity_cleanup()
2026-07-08 15:44 ` Biren Pandya
@ 2026-07-08 15:44 ` Biren Pandya
0 siblings, 0 replies; 7+ messages in thread
From: Biren Pandya @ 2026-07-08 15:44 UTC (permalink / raw)
To: jacopo+renesas, kieran.bingham+renesas, laurent.pinchart+renesas,
Niklas Söderlund, mchehab, sakari.ailus, linux-media,
linux-kernel
Cc: 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")
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
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(-)
diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
index bcab462708c70..531b71d0a94df 100644
--- a/drivers/media/i2c/rdacm21.c
+++ b/drivers/media/i2c/rdacm21.c
@@ -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:
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] media: i2c: rdacm21: Fix missing media_entity_cleanup()
2026-06-21 6:07 [PATCH v2] " Biren Pandya
@ 2026-06-22 7:58 ` Jacopo Mondi
0 siblings, 0 replies; 7+ messages in thread
From: Jacopo Mondi @ 2026-06-22 7:58 UTC (permalink / raw)
To: Biren Pandya
Cc: Jacopo Mondi, Kieran Bingham, Laurent Pinchart,
Niklas Söderlund, Mauro Carvalho Chehab, Sakari Ailus,
open list:RDACM21 Camera Sensor, open list, stable
Hi Biren
On Sun, Jun 21, 2026 at 11:37:06AM +0530, Biren Pandya wrote:
> 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")
> Cc: stable@vger.kernel.org
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.
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> ---
> drivers/media/i2c/rdacm21.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
> index bcab462708c7..41d4242a9b58 100644
> --- a/drivers/media/i2c/rdacm21.c
> +++ b/drivers/media/i2c/rdacm21.c
> @@ -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
> 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)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] media: i2c: rdacm21: Fix missing media_entity_cleanup()
@ 2026-06-21 6:07 Biren Pandya
2026-06-22 7:58 ` Jacopo Mondi
0 siblings, 1 reply; 7+ messages in thread
From: Biren Pandya @ 2026-06-21 6:07 UTC (permalink / raw)
To: Jacopo Mondi, Kieran Bingham, Laurent Pinchart,
Niklas Söderlund, Mauro Carvalho Chehab, Sakari Ailus,
open list:RDACM21 Camera Sensor, open list
Cc: Biren Pandya, stable
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")
Cc: stable@vger.kernel.org
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
drivers/media/i2c/rdacm21.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/media/i2c/rdacm21.c b/drivers/media/i2c/rdacm21.c
index bcab462708c7..41d4242a9b58 100644
--- a/drivers/media/i2c/rdacm21.c
+++ b/drivers/media/i2c/rdacm21.c
@@ -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);
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-08 15:44 UTC | newest]
Thread overview: 7+ 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-21 6:07 [PATCH v2] " Biren Pandya
2026-06-22 7:58 ` Jacopo Mondi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome