[PATCH] OPP: of: Fix potential memory leak in opp_parse_supplies()

Abdun Nihaal posted 1 patch 1 month ago
drivers/opp/of.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] OPP: of: Fix potential memory leak in opp_parse_supplies()
Posted by Abdun Nihaal 1 month ago
The memory allocated for microvolt, microamp and microwatt is not freed
in one of the paths in opp_parse_supplies() which returns directly.
Fix that by adding a goto to the error unwind ladder.

Fixes: 2eedf62e66c2 ("OPP: decouple dt properties in opp_parse_supplies()")
Cc: stable@vger.kernel.org
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Compile tested only. Issue found using static analysis.

 drivers/opp/of.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index f96adfd5b219..c02e20632fa6 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -673,7 +673,7 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
 	 */
 	if (unlikely(opp_table->regulator_count == -1)) {
 		opp_table->regulator_count = 0;
-		return 0;
+		goto free_microwatt;
 	}
 
 	for (i = 0, j = 0; i < opp_table->regulator_count; i++) {
@@ -696,6 +696,7 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
 			opp->supplies[i].u_watt = microwatt[i];
 	}
 
+free_microwatt:
 	kfree(microwatt);
 free_microamp:
 	kfree(microamp);
-- 
2.43.0
Re: [PATCH] OPP: of: Fix potential memory leak in opp_parse_supplies()
Posted by Viresh Kumar 3 weeks, 2 days ago
On 11-05-26, 12:12, Abdun Nihaal wrote:
> The memory allocated for microvolt, microamp and microwatt is not freed
> in one of the paths in opp_parse_supplies() which returns directly.
> Fix that by adding a goto to the error unwind ladder.
> 
> Fixes: 2eedf62e66c2 ("OPP: decouple dt properties in opp_parse_supplies()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
> ---
> Compile tested only. Issue found using static analysis.
> 
>  drivers/opp/of.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied. Thanks.

-- 
viresh