From: Zhang Qilong Date: Mon, 21 Nov 2022 01:18:31 +0000 (+0800) Subject: power: supply: z2_battery: Fix possible memleak in z2_batt_probe() X-Git-Tag: v6.2-rc1~58^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=955bee204f3dd307642c101b75e370662987e735;p=thirdparty%2Fkernel%2Fstable.git power: supply: z2_battery: Fix possible memleak in z2_batt_probe() If devm_gpiod_get_optional() returns error, the charger should be freed before z2_batt_probe returns according to the context. We fix it by just gotoing to 'err' branch. Fixes: a3b4388ea19b ("power: supply: z2_battery: Convert to GPIO descriptors") Signed-off-by: Zhang Qilong Reviewed-by: Linus Walleij Signed-off-by: Sebastian Reichel --- diff --git a/drivers/power/supply/z2_battery.c b/drivers/power/supply/z2_battery.c index eb01b01bf593b..0ba4a590a0a5f 100644 --- a/drivers/power/supply/z2_battery.c +++ b/drivers/power/supply/z2_battery.c @@ -205,10 +205,12 @@ static int z2_batt_probe(struct i2c_client *client) charger->charge_gpiod = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_IN); - if (IS_ERR(charger->charge_gpiod)) - return dev_err_probe(&client->dev, + if (IS_ERR(charger->charge_gpiod)) { + ret = dev_err_probe(&client->dev, PTR_ERR(charger->charge_gpiod), "failed to get charge GPIO\n"); + goto err; + } if (charger->charge_gpiod) { gpiod_set_consumer_name(charger->charge_gpiod, "BATT CHRG");