Skip to content

Commit 77adf4b

Browse files
javiercarrascocruzgregkh
authored andcommitted
spmi: pmic-arb: fix return path in for_each_available_child_of_node()
This loop requires explicit calls to of_node_put() upon early exits (break, goto, return) to decrement the child refcounter and avoid memory leaks if the child is not required out of the loop. A more robust solution is using the scoped variant of the macro, which automatically calls of_node_put() when the child goes out of scope. Cc: [email protected] Fixes: 9799873 ("spmi: pmic-arb: Add multi bus support") Signed-off-by: Javier Carrasco <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Neil Armstrong <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5de07b8 commit 77adf4b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/spmi/spmi-pmic-arb.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,14 +1763,13 @@ static int spmi_pmic_arb_register_buses(struct spmi_pmic_arb *pmic_arb,
17631763
{
17641764
struct device *dev = &pdev->dev;
17651765
struct device_node *node = dev->of_node;
1766-
struct device_node *child;
17671766
int ret;
17681767

17691768
/* legacy mode doesn't provide child node for the bus */
17701769
if (of_device_is_compatible(node, "qcom,spmi-pmic-arb"))
17711770
return spmi_pmic_arb_bus_init(pdev, node, pmic_arb);
17721771

1773-
for_each_available_child_of_node(node, child) {
1772+
for_each_available_child_of_node_scoped(node, child) {
17741773
if (of_node_name_eq(child, "spmi")) {
17751774
ret = spmi_pmic_arb_bus_init(pdev, child, pmic_arb);
17761775
if (ret)

0 commit comments

Comments
 (0)