power: supply: cpcap-charger: Fix power_supply_put on null battery pointer
authorColin Ian King <colin.king@canonical.com>
Fri, 15 Jan 2021 13:15:24 +0000 (13:15 +0000)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 15 Jan 2021 14:15:30 +0000 (15:15 +0100)
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>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/cpcap-charger.c

index 823d666f09e0e3bba246373b2431537f4537aaa7..641dcad1133f76b8f544583672033673cc32b715 100644 (file)
@@ -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;
 }