Skip to contentSkip to conversation

media: v4l2-fwnode: Improve exception handling in v4l2_fwnode_connector_add_link()

PATCH In review Markus Elfring 2 participants 2 messages Mar 1, 2024 – Mar 4, 2024

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

PATCH 1/1 media: v4l2-fwnode: Improve exception handling in v4l2_fwnode_connector_add_link()

From: Markus Elfring <[email protected]>
Date: Fri, 1 Mar 2024 15:02:09 +0100

The kfree() function was called in one case by
the v4l2_fwnode_connector_add_link() function during error handling even if the passed variable contained a null pointer. Thus use another label.

---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-fwnode.c +2 -1
index 89c7192148df..dc6daf3a9a51 100644
@@ -744,7 +744,7 @@ int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
 	link = kzalloc(sizeof(*link), GFP_KERNEL);
 	if (!link) {
 		err = -ENOMEM;
-		goto err;
+		goto put_fwnode_ep;
 	}
 
 	err = v4l2_fwnode_parse_link(connector_ep, &link->fwnode_link);
@@ -760,6 +760,7 @@ int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
 
 err:
 	kfree(link);
+put_fwnode_ep:
 	fwnode_handle_put(connector_ep);
 
 	return err;

--
2.44.0

maintainer
#1 lore raw

Hi Markus,

Quoted 7 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Fri, 1 Mar 2024 15:02:09 +0100

The kfree() function was called in one case by
the v4l2_fwnode_connector_add_link() function during error handling even if the passed variable contained a null pointer. Thus use another label.

This isn't a problem, the code is fine as-is.

Quoted 30 lines
---
 drivers/media/v4l2-core/v4l2-fwnode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-fwnode.c +2 -2
index 89c7192148df..dc6daf3a9a51 100644
@@ -744,7 +744,7 @@ int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
 	link = kzalloc(sizeof(*link), GFP_KERNEL);
 	if (!link) {
 		err = -ENOMEM;
-		goto err;
+		goto put_fwnode_ep;
 	}
 
 	err = v4l2_fwnode_parse_link(connector_ep, &link->fwnode_link);
@@ -760,6 +760,7 @@ int v4l2_fwnode_connector_add_link(struct fwnode_handle *fwnode,
 
 err:
 	kfree(link);
+put_fwnode_ep:
 	fwnode_handle_put(connector_ep);
 
 	return err;
--

2.44.0

Signature · 1 line
Sakari Ailus