Skip to contentSkip to conversation

platform/x86/amd/pmf: Fix power supply leak in amd_pmf_get_battery_prop()

PATCH In review Wentao Liang 2 participants 2 messages Sep 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86/amd/pmf: Fix power supply leak in amd_pmf_get_battery_prop()

power_supply_get_by_name() takes a reference that is only dropped on the error path of power_supply_get_property(). Drop it as soon as the property has been read and stop searching, so that a successful lookup does not leak the reference.

Fixes f4627dfd0e19 ("platform/x86/amd/pmf: Add support to get inputs from other subsystems")
---
 drivers/platform/x86/amd/pmf/spc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/pmf/spc.c +4 -3
index f48678a23cc7..cd957d7a4e48 100644
@@ -249,10 +249,11 @@ static int amd_pmf_get_battery_prop(enum power_supply_property prop)
 			continue;
 
 		ret = power_supply_get_property(psy, prop, &value);
-		if (ret) {
-			power_supply_put(psy);
+		power_supply_put(psy);
+		if (ret)
 			return ret;
-		}
+
+		break;
 	}
 
 	return value.intval;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Wentao Liang

power_supply_get_by_name() takes a reference that is only dropped on the error path of power_supply_get_property(). Drop it as soon as the property has been read and stop searching, so that a successful lookup does not leak the reference.

Fixes f4627dfd0e19 ("platform/x86/amd/pmf: Add support to get inputs from other subsystems")
Quoted 22 lines
  drivers/platform/x86/amd/pmf/spc.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/pmf/spc.c +4 -3
index f48678a23cc7..cd957d7a4e48 100644
@@ -249,10 +249,11 @@ static int amd_pmf_get_battery_prop(enum power_supply_property prop)
  			continue;
 
  		ret = power_supply_get_property(psy, prop, &value);
-		if (ret) {
-			power_supply_put(psy);
+		power_supply_put(psy);
+		if (ret)
  			return ret;
-		}
+
+		break;
  	}
 
  	return value.intval;