* [PATCH] spmi: pmic-arb: fix return path in for_each_available_child_of_node()
@ 2024-10-01 12:55 Javier Carrasco
2024-10-01 13:16 ` Neil Armstrong
2024-10-09 22:31 ` Stephen Boyd
0 siblings, 2 replies; 3+ messages in thread
From: Javier Carrasco @ 2024-10-01 12:55 UTC (permalink / raw)
To: Stephen Boyd, Neil Armstrong, Abel Vesa, Greg Kroah-Hartman
Cc: linux-kernel, stable, Javier Carrasco
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>
---
drivers/spmi/spmi-pmic-arb.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c
index 9ba9495fcc4b..ea843159b745 100644
--- a/drivers/spmi/spmi-pmic-arb.c
+++ b/drivers/spmi/spmi-pmic-arb.c
@@ -1763,14 +1763,13 @@ static int spmi_pmic_arb_register_buses(struct spmi_pmic_arb *pmic_arb,
{
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
- struct device_node *child;
int ret;
/* legacy mode doesn't provide child node for the bus */
if (of_device_is_compatible(node, "qcom,spmi-pmic-arb"))
return spmi_pmic_arb_bus_init(pdev, node, pmic_arb);
- for_each_available_child_of_node(node, child) {
+ for_each_available_child_of_node_scoped(node, child) {
if (of_node_name_eq(child, "spmi")) {
ret = spmi_pmic_arb_bus_init(pdev, child, pmic_arb);
if (ret)
---
base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
change-id: 20241001-spmi-pmic-arb-scoped-a4b90179edef
Best regards,
--
Javier Carrasco <javier.carrasco.cruz@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] spmi: pmic-arb: fix return path in for_each_available_child_of_node()
2024-10-01 12:55 [PATCH] spmi: pmic-arb: fix return path in for_each_available_child_of_node() Javier Carrasco
@ 2024-10-01 13:16 ` Neil Armstrong
2024-10-09 22:31 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Neil Armstrong @ 2024-10-01 13:16 UTC (permalink / raw)
To: Javier Carrasco, Stephen Boyd, Abel Vesa, Greg Kroah-Hartman
Cc: linux-kernel, stable
Le 01/10/2024 à 14:55, Javier Carrasco a écrit :
> 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>
> ---
> drivers/spmi/spmi-pmic-arb.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c
> index 9ba9495fcc4b..ea843159b745 100644
> --- a/drivers/spmi/spmi-pmic-arb.c
> +++ b/drivers/spmi/spmi-pmic-arb.c
> @@ -1763,14 +1763,13 @@ static int spmi_pmic_arb_register_buses(struct spmi_pmic_arb *pmic_arb,
> {
> struct device *dev = &pdev->dev;
> struct device_node *node = dev->of_node;
> - struct device_node *child;
> int ret;
>
> /* legacy mode doesn't provide child node for the bus */
> if (of_device_is_compatible(node, "qcom,spmi-pmic-arb"))
> return spmi_pmic_arb_bus_init(pdev, node, pmic_arb);
>
> - for_each_available_child_of_node(node, child) {
> + for_each_available_child_of_node_scoped(node, child) {
> if (of_node_name_eq(child, "spmi")) {
> ret = spmi_pmic_arb_bus_init(pdev, child, pmic_arb);
> if (ret)
>
> ---
> base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
> change-id: 20241001-spmi-pmic-arb-scoped-a4b90179edef
>
> Best regards,
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] spmi: pmic-arb: fix return path in for_each_available_child_of_node()
2024-10-01 12:55 [PATCH] spmi: pmic-arb: fix return path in for_each_available_child_of_node() Javier Carrasco
2024-10-01 13:16 ` Neil Armstrong
@ 2024-10-09 22:31 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2024-10-09 22:31 UTC (permalink / raw)
To: Abel Vesa, Greg Kroah-Hartman, Javier Carrasco, Neil Armstrong
Cc: linux-kernel, stable, Javier Carrasco
Quoting Javier Carrasco (2024-10-01 05:55:52)
> 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>
> ---
Applied to spmi-next
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-09 22:31 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01 12:55 [PATCH] spmi: pmic-arb: fix return path in for_each_available_child_of_node() Javier Carrasco
2024-10-01 13:16 ` Neil Armstrong
2024-10-09 22:31 ` Stephen Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox