[PATCH] power: supply: cpcap-battery: Fix nvmem device leak in cpcap_battery_detect_battery_type()

From: Wentao Liang

Date: Thu Sep 17 2026 - 10:26:42 EST


cpcap_battery_detect_battery_type() takes a reference on the nvmem
device with nvmem_device_find(), but never releases it, so the
reference leaks on every call. Drop it once the battery ID has been
read.

Fixes: fd46821e85de ("power: supply: cpcap-battery: Add battery type auto detection for mapphone devices")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/power/supply/cpcap-battery.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 7b7bdce3162f..b7ed4f2d3826 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -445,6 +445,9 @@ static void cpcap_battery_detect_battery_type(struct cpcap_battery_ddata *ddata)
dev_warn(ddata->dev, "Can not read battery nvmem device. Assuming generic lipo battery\n");
}

+ if (!IS_ERR_OR_NULL(nvmem))
+ nvmem_device_put(nvmem);
+
switch (battery_id) {
case CPCAP_BATTERY_EB41_HW4X_ID:
ddata->config = cpcap_battery_eb41_data;
--
2.34.1