Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: stable@vger.kernel.org
Fixes: 979987371739 ("spmi: pmic-arb: Add multi bus support")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20241001-spmi-pmic-arb-scoped-v1-1-5872bab34ed6@gmail.com
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Link: https://lore.kernel.org/r/20241109002829.160973-2-sboyd@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Javier Carrasco and committed by
Greg Kroah-Hartman
77adf4b1 5de07b8a

+1 -2
+1 -2
drivers/spmi/spmi-pmic-arb.c
··· 1763 1763 { 1764 1764 struct device *dev = &pdev->dev; 1765 1765 struct device_node *node = dev->of_node; 1766 - struct device_node *child; 1767 1766 int ret; 1768 1767 1769 1768 /* legacy mode doesn't provide child node for the bus */ 1770 1769 if (of_device_is_compatible(node, "qcom,spmi-pmic-arb")) 1771 1770 return spmi_pmic_arb_bus_init(pdev, node, pmic_arb); 1772 1771 1773 - for_each_available_child_of_node(node, child) { 1772 + for_each_available_child_of_node_scoped(node, child) { 1774 1773 if (of_node_name_eq(child, "spmi")) { 1775 1774 ret = spmi_pmic_arb_bus_init(pdev, child, pmic_arb); 1776 1775 if (ret)