Skip to content

Commit

Permalink
usb: core: add missing of_node_put() in usb_of_has_devices_or_graph
Browse files Browse the repository at this point in the history
The for_each_child_of_node() macro requires an explicit call to
of_node_put() on early exits to decrement the child refcount and avoid a
memory leak.
The child node is not required outsie the loop, and the resource must be
released before the function returns.

Add the missing of_node_put().

Cc: [email protected]
Fixes: 82e8213 ("usb: core: Set connect_type of ports based on DT node")
Signed-off-by: Javier Carrasco <[email protected]>
Reviewed-by: Stephen Boyd <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
javiercarrascocruz authored and gregkh committed Jul 3, 2024
1 parent 3859e85 commit c7a5403
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/usb/core/of.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ static bool usb_of_has_devices_or_graph(const struct usb_device *hub)
if (of_graph_is_present(np))
return true;

for_each_child_of_node(np, child)
if (of_property_present(child, "reg"))
for_each_child_of_node(np, child) {
if (of_property_present(child, "reg")) {
of_node_put(child);
return true;
}
}

return false;
}
Expand Down

0 comments on commit c7a5403

Please sign in to comment.