platform/x86/amd/pmf: Fix power supply leak in amd_pmf_get_battery_prop()
Subsystems (3)
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")
Signed-off-by Wentao Liang <[email protected]>
--- drivers/platform/x86/amd/pmf/spc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/pmf/spc.c +4 -3
@@ -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
Quoted 8 lines · Wentao Liang
power_supply_get_by_name()takes a reference that is only dropped on the error path ofpower_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")Signed-off-by Wentao Liang <[email protected]>
Reviewed-by Mario Limonciello (AMD) <[email protected]>> ---
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@@ -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;