Skip to content

Commit 39af728

Browse files
Yang Yinglianggregkh
authored andcommitted
device property: fix of node refcount leak in fwnode_graph_get_next_endpoint()
The 'parent' returned by fwnode_graph_get_port_parent() with refcount incremented when 'prev' is not NULL, it needs be put when finish using it. Because the parent is const, introduce a new variable to store the returned fwnode, then put it before returning from fwnode_graph_get_next_endpoint(). Fixes: b5b41ab ("device property: Check fwnode->secondary in fwnode_graph_get_next_endpoint()") Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-and-tested-by: Daniel Scally <djrscally@gmail.com> Link: https://lore.kernel.org/r/20221123022542.2999510-1-yangyingliang@huawei.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b7bfaa7 commit 39af728

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/base/property.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,32 @@ struct fwnode_handle *
997997
fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
998998
struct fwnode_handle *prev)
999999
{
1000+
struct fwnode_handle *ep, *port_parent = NULL;
10001001
const struct fwnode_handle *parent;
1001-
struct fwnode_handle *ep;
10021002

10031003
/*
10041004
* If this function is in a loop and the previous iteration returned
10051005
* an endpoint from fwnode->secondary, then we need to use the secondary
10061006
* as parent rather than @fwnode.
10071007
*/
1008-
if (prev)
1009-
parent = fwnode_graph_get_port_parent(prev);
1010-
else
1008+
if (prev) {
1009+
port_parent = fwnode_graph_get_port_parent(prev);
1010+
parent = port_parent;
1011+
} else {
10111012
parent = fwnode;
1013+
}
10121014
if (IS_ERR_OR_NULL(parent))
10131015
return NULL;
10141016

10151017
ep = fwnode_call_ptr_op(parent, graph_get_next_endpoint, prev);
10161018
if (ep)
1017-
return ep;
1019+
goto out_put_port_parent;
1020+
1021+
ep = fwnode_graph_get_next_endpoint(parent->secondary, NULL);
10181022

1019-
return fwnode_graph_get_next_endpoint(parent->secondary, NULL);
1023+
out_put_port_parent:
1024+
fwnode_handle_put(port_parent);
1025+
return ep;
10201026
}
10211027
EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
10221028

0 commit comments

Comments
 (0)