media: v4l2-core: Fix a potential resource leak in v4l2_fwnode_parse_link()
[ Upstream commitd7b13edd4c] If fwnode_graph_get_remote_endpoint() fails, 'fwnode' is known to be NULL, so fwnode_handle_put() is a no-op. Release the reference taken from a previous fwnode_graph_get_port_parent() call instead. Also handle fwnode_graph_get_port_parent() failures. In order to fix these issues, add an error handling path to the function and the needed gotos. Fixes:ca50c197bd("[media] v4l: fwnode: Support generic fwnode for parsing standardised properties") Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
5865926da2
commit
d8a8f75fce
@@ -572,19 +572,29 @@ int v4l2_fwnode_parse_link(struct fwnode_handle *fwnode,
|
|||||||
link->local_id = fwep.id;
|
link->local_id = fwep.id;
|
||||||
link->local_port = fwep.port;
|
link->local_port = fwep.port;
|
||||||
link->local_node = fwnode_graph_get_port_parent(fwnode);
|
link->local_node = fwnode_graph_get_port_parent(fwnode);
|
||||||
|
if (!link->local_node)
|
||||||
|
return -ENOLINK;
|
||||||
|
|
||||||
fwnode = fwnode_graph_get_remote_endpoint(fwnode);
|
fwnode = fwnode_graph_get_remote_endpoint(fwnode);
|
||||||
if (!fwnode) {
|
if (!fwnode)
|
||||||
fwnode_handle_put(fwnode);
|
goto err_put_local_node;
|
||||||
return -ENOLINK;
|
|
||||||
}
|
|
||||||
|
|
||||||
fwnode_graph_parse_endpoint(fwnode, &fwep);
|
fwnode_graph_parse_endpoint(fwnode, &fwep);
|
||||||
link->remote_id = fwep.id;
|
link->remote_id = fwep.id;
|
||||||
link->remote_port = fwep.port;
|
link->remote_port = fwep.port;
|
||||||
link->remote_node = fwnode_graph_get_port_parent(fwnode);
|
link->remote_node = fwnode_graph_get_port_parent(fwnode);
|
||||||
|
if (!link->remote_node)
|
||||||
|
goto err_put_remote_endpoint;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_put_remote_endpoint:
|
||||||
|
fwnode_handle_put(fwnode);
|
||||||
|
|
||||||
|
err_put_local_node:
|
||||||
|
fwnode_handle_put(link->local_node);
|
||||||
|
|
||||||
|
return -ENOLINK;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link);
|
EXPORT_SYMBOL_GPL(v4l2_fwnode_parse_link);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user