]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: charger-manager: fix refcount leak in is_full_charged()
authorWenTao Liang <vulab@iscas.ac.cn>
Thu, 11 Jun 2026 00:53:21 +0000 (08:53 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 12 Jun 2026 22:00:56 +0000 (00:00 +0200)
In is_full_charged(), power_supply_get_by_name() is called to
obtain a reference to the fuel_gauge power supply. If the
voltage check (uV >= desc->fullbatt_uV) succeeds, the function
returns true directly without releasing the reference, leaking
the refcount.

Fix this by setting a flag and jumping to the out label where
power_supply_put() properly drops the reference.

Cc: stable@vger.kernel.org
Fixes: e132fc6bb89b ("power: supply: charger-manager: Make decisions focussed on battery status")
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
Link: https://patch.msgid.link/20260611005322.53096-1-vulab@iscas.ac.cn
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/charger-manager.c

index 5dc9cd37d6977d7ad9308c528155fd23980d8dde..10158b1bf8e2f0043f6a2185dd4aa55eadba2963 100644 (file)
@@ -303,8 +303,10 @@ static bool is_full_charged(struct charger_manager *cm)
                        if (cm->battery_status == POWER_SUPPLY_STATUS_FULL
                                        && desc->fullbatt_vchkdrop_uV)
                                uV += desc->fullbatt_vchkdrop_uV;
-                       if (uV >= desc->fullbatt_uV)
-                               return true;
+                       if (uV >= desc->fullbatt_uV) {
+                               is_full = true;
+                               goto out;
+                       }
                }
        }