diff mbox series

[next] power: supply: cpcap-charger: Fix power_supply_put on null battery pointer

Message ID 20210115131524.71339-1-colin.king@canonical.com
State Accepted
Commit 39196cfe10dd2b46ee28b44abbc0db4f4cb7822f
Headers show
Series [next] power: supply: cpcap-charger: Fix power_supply_put on null battery pointer | expand

Commit Message

Colin King Jan. 15, 2021, 1:15 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently if the pointer battery is null there is a null pointer
dereference on the call to power_supply_put.  Fix this by only
performing the put if battery is not null.

Addresses-Coverity: ("Dereference after null check")
Fixes: 4bff91bb3231 ("power: supply: cpcap-charger: Fix missing power_supply_put()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/power/supply/cpcap-charger.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
index 823d666f09e0..641dcad1133f 100644
--- a/drivers/power/supply/cpcap-charger.c
+++ b/drivers/power/supply/cpcap-charger.c
@@ -300,8 +300,9 @@  cpcap_charger_get_bat_const_charge_voltage(struct cpcap_charger_ddata *ddata)
 				&prop);
 		if (!error)
 			voltage = prop.intval;
+
+		power_supply_put(battery);
 	}
-	power_supply_put(battery);
 
 	return voltage;
 }