[PATCH 5.15 218/779] regulator: of: Fix refcount leak bug in of_get_regulation_constraints()

Greg Kroah-Hartman posted 779 patches 3 years, 4 months ago
[PATCH 5.15 218/779] regulator: of: Fix refcount leak bug in of_get_regulation_constraints()
Posted by Greg Kroah-Hartman 3 years, 4 months ago
From: Liang He <windhl@126.com>

[ Upstream commit 66efb665cd5ad69b27dca8571bf89fc6b9c628a4 ]

We should call the of_node_put() for the reference returned by
of_get_child_by_name() which has increased the refcount.

Fixes: 40e20d68bb3f ("regulator: of: Add support for parsing regulator_state for suspend state")
Signed-off-by: Liang He <windhl@126.com>
Link: https://lore.kernel.org/r/20220715111027.391032-1-windhl@126.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/regulator/of_regulator.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index f54d4f176882..e12b681c72e5 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -264,8 +264,12 @@ static int of_get_regulation_constraints(struct device *dev,
 		}
 
 		suspend_np = of_get_child_by_name(np, regulator_states[i]);
-		if (!suspend_np || !suspend_state)
+		if (!suspend_np)
 			continue;
+		if (!suspend_state) {
+			of_node_put(suspend_np);
+			continue;
+		}
 
 		if (!of_property_read_u32(suspend_np, "regulator-mode",
 					  &pval)) {
-- 
2.35.1
Re: [PATCH 5.15 218/779] regulator: of: Fix refcount leak bug in of_get_regulation_constraints()
Posted by Pavel Machek 3 years, 3 months ago
Hi!

> From: Liang He <windhl@126.com>
> 
> [ Upstream commit 66efb665cd5ad69b27dca8571bf89fc6b9c628a4 ]
> 
> We should call the of_node_put() for the reference returned by
> of_get_child_by_name() which has increased the refcount.

Looks okay,

> +++ b/drivers/regulator/of_regulator.c
> @@ -264,8 +264,12 @@ static int of_get_regulation_constraints(struct device *dev,
>  		}
>  
>  		suspend_np = of_get_child_by_name(np, regulator_states[i]);
> -		if (!suspend_np || !suspend_state)
> +		if (!suspend_np)
>  			continue;
> +		if (!suspend_state) {
> +			of_node_put(suspend_np);
> +			continue;
> +		}
>  

but note that of_node_put(NULL) should be okay, so this can be cleaned
up.

Best regards,
								Pavel
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany