Skip to contentSkip to conversation

media: v4l2-core: Fix memory leak in v4l2_fwnode_parse_link

PATCH In review Biren Pandya 2 participants 2 messages Jun 19 – Jul 8

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

PATCH v2 1/1 media: v4l2-core: Fix memory leak in v4l2_fwnode_parse_link

In v4l2_fwnode_parse_link(), the remote endpoint fwnode reference is acquired using fwnode_graph_get_remote_endpoint(). This reference is properly released in the error paths, but it is leaked on the success path.

Add the missing fwnode_handle_put() before returning 0 to prevent the reference leak.

---
Changes in v2:
- Resend because the v1 patch was lost in transit and did not appear on lore.kernel.org, causing CI to fail looking for the message ID. No code changes.

 drivers/media/v4l2-core/v4l2-fwnode.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-fwnode.c +1 -0
index 77f3298821b5..93ef83c591ef 100644
@@ -633,6 +633,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
 	if (!link->remote_node)
 		goto err_put_remote_endpoint;
 
+	fwnode_handle_put(fwnode);
 	return 0;
 
 err_put_remote_endpoint:
Signature · 1 line
2.50.1 (Apple Git-155)
maintainer
#1 lore raw

Hi Biren,

Thanks for the patch.

The subject prefix should be s/core/fwnode/; please see earlier patches for hints in the future.

Quoted 21 lines · Biren Pandya

In v4l2_fwnode_parse_link(), the remote endpoint fwnode reference is acquired using fwnode_graph_get_remote_endpoint(). This reference is properly released in the error paths, but it is leaked on the success path.

Add the missing fwnode_handle_put() before returning 0 to prevent the reference leak.

---
Changes in v2:
- Resend because the v1 patch was lost in transit and did not appear on lore.kernel.org, causing CI to fail looking for the message ID. No code changes.

 drivers/media/v4l2-core/v4l2-fwnode.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/v4l2-core/v4l2-fwnode.c +0 -0
index 77f3298821b5..93ef83c591ef 100644

drivers/media/v4l2-core/v4l2-fwnode.c int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode, · line 636

Quoted 4 lines
drivers/media/v4l2-core/v4l2-fwnode.c +1 -0
@@ -633,6 +633,7 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
 	if (!link->remote_node)
 		goto err_put_remote_endpoint;
 
+	fwnode_handle_put(fwnode);

A newline here. I'll address these this time.

Quoted 3 lines
drivers/media/v4l2-core/v4l2-fwnode.c +0 -0
 	return 0;
 
 err_put_remote_endpoint:
Signature · 3 lines
Kind regards,

Sakari Ailus