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

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: 4bff91bb32 ("power: supply: cpcap-charger: Fix missing power_supply_put()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
Colin Ian King 2021-01-15 13:15:24 +00:00 committed by Sebastian Reichel
parent 51567ad125
commit 39196cfe10
1 changed files with 2 additions and 1 deletions

View File

@ -300,8 +300,9 @@ cpcap_charger_get_bat_const_charge_voltage(struct cpcap_charger_ddata *ddata)
&prop); &prop);
if (!error) if (!error)
voltage = prop.intval; voltage = prop.intval;
power_supply_put(battery);
} }
power_supply_put(battery);
return voltage; return voltage;
} }