mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] media: v4l2-core: Drop manual fwnode_handle_put() via scope-based cleanup
@ 2026-06-19  8:01 Biren Pandya
  2026-07-30  7:52 ` Sakari Ailus
  0 siblings, 1 reply; 2+ messages in thread
From: Biren Pandya @ 2026-06-19  8:01 UTC (permalink / raw)
  To: sakari.ailus, laurent.pinchart, mchehab
  Cc: linux-media, linux-kernel, Biren Pandya

Simplify v4l2_subdev_get_fwnode_pad_1_to_1() by converting the local
fwnode variable to use the __free(fwnode_handle) scope-based cleanup
macro.

This removes the need for manual fwnode_handle_put() calls and naturally
ensures the fwnode reference is held during the device_match_fwnode()
comparison.

Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
Changes in v3:
- Resend as a standalone patch to resolve Media CI robot grouping error caused by duplicate Message-IDs in the v2 thread. No code changes.
- Link to v2: https://lore.kernel.org/all/20260616162208.56488-2-birenpandya@gmail.com/

Changes in v2:
- Updated the commit message to remove the "Use-After-Free" language,
  as there is no vulnerability in practice.
- Adjusted the implementation to declare `struct fwnode_handle *fwnode`
  directly at the point of initialization, rather than at the top of the
  block, conforming to recommended usage.
- Renamed the patch subject to better reflect the true nature of the change.
- Link to v1: https://lore.kernel.org/all/20260616092516.46339-1-birenpandya@gmail.com/

 drivers/media/v4l2-core/v4l2-subdev.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index e6b133ef7850..806b059410ce 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -1243,15 +1243,14 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
 int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
 				      struct fwnode_endpoint *endpoint)
 {
-	struct fwnode_handle *fwnode;
+	struct fwnode_handle *fwnode __free(fwnode_handle) =
+		fwnode_graph_get_port_parent(endpoint->local_fwnode);
 	struct v4l2_subdev *sd;
 
 	if (!is_media_entity_v4l2_subdev(entity))
 		return -EINVAL;
 
 	sd = media_entity_to_v4l2_subdev(entity);
 
-	fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode);
-	fwnode_handle_put(fwnode);
 
 	if (device_match_fwnode(sd->dev, fwnode))
 		return endpoint->port;
 
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] media: v4l2-core: Drop manual fwnode_handle_put() via scope-based cleanup
  2026-06-19  8:01 [PATCH v3] media: v4l2-core: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
@ 2026-07-30  7:52 ` Sakari Ailus
  0 siblings, 0 replies; 2+ messages in thread
From: Sakari Ailus @ 2026-07-30  7:52 UTC (permalink / raw)
  To: Biren Pandya; +Cc: laurent.pinchart, mchehab, linux-media, linux-kernel

Hi Biren,

On the subject: s/core/subdev/ .

On Fri, Jun 19, 2026 at 01:31:33PM +0530, Biren Pandya wrote:
> Simplify v4l2_subdev_get_fwnode_pad_1_to_1() by converting the local
> fwnode variable to use the __free(fwnode_handle) scope-based cleanup
> macro.
> 
> This removes the need for manual fwnode_handle_put() calls and naturally
> ensures the fwnode reference is held during the device_match_fwnode()
> comparison.
> 
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> ---
> Changes in v3:
> - Resend as a standalone patch to resolve Media CI robot grouping error caused by duplicate Message-IDs in the v2 thread. No code changes.
> - Link to v2: https://lore.kernel.org/all/20260616162208.56488-2-birenpandya@gmail.com/
> 
> Changes in v2:
> - Updated the commit message to remove the "Use-After-Free" language,
>   as there is no vulnerability in practice.
> - Adjusted the implementation to declare `struct fwnode_handle *fwnode`
>   directly at the point of initialization, rather than at the top of the
>   block, conforming to recommended usage.
> - Renamed the patch subject to better reflect the true nature of the change.
> - Link to v1: https://lore.kernel.org/all/20260616092516.46339-1-birenpandya@gmail.com/
> 
>  drivers/media/v4l2-core/v4l2-subdev.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index e6b133ef7850..806b059410ce 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -1243,15 +1243,14 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
>  int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
>  				      struct fwnode_endpoint *endpoint)
>  {
> -	struct fwnode_handle *fwnode;
> +	struct fwnode_handle *fwnode __free(fwnode_handle) =

__free() is declared in linux/cleanup.h.

> +		fwnode_graph_get_port_parent(endpoint->local_fwnode);

Can you declare this where fwnode_graph_get_port_parent() was called
previously?

>  	struct v4l2_subdev *sd;
>  
>  	if (!is_media_entity_v4l2_subdev(entity))
>  		return -EINVAL;
>  
>  	sd = media_entity_to_v4l2_subdev(entity);
>  
> -	fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode);
> -	fwnode_handle_put(fwnode);
>  
>  	if (device_match_fwnode(sd->dev, fwnode))
>  		return endpoint->port;
>  

-- 
Regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-30  7:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-19  8:01 [PATCH v3] media: v4l2-core: Drop manual fwnode_handle_put() via scope-based cleanup Biren Pandya
2026-07-30  7:52 ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®