Re: [PATCH] platform/x86/amd/pmf: Fix power supply leak in amd_pmf_get_battery_prop()
From: Mario Limonciello
Date: Thu Sep 17 2026 - 16:21:07 EST
On 9/17/26 09:01, Wentao Liang wrote:
power_supply_get_by_name() takes a reference that is only dropped onReviewed-by: Mario Limonciello (AMD) <superm1@xxxxxxxxxx>> ---
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")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
drivers/platform/x86/amd/pmf/spc.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/amd/pmf/spc.c b/drivers/platform/x86/amd/pmf/spc.c
index f48678a23cc7..cd957d7a4e48 100644
--- a/drivers/platform/x86/amd/pmf/spc.c
+++ b/drivers/platform/x86/amd/pmf/spc.c
@@ -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;