drivers/platform/x86/amd/pmf/spc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
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")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
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;
--
2.34.1
On 9/17/26 09:01, Wentao Liang wrote:
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>> ---
> 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;
© 2016 - 2026 Red Hat, Inc.