Skip to content

Commit 955bee2

Browse files
Zhang Qilongsre
authored andcommitted
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: a3b4388 ("power: supply: z2_battery: Convert to GPIO descriptors") Signed-off-by: Zhang Qilong <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 922bde5 commit 955bee2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/power/supply/z2_battery.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ static int z2_batt_probe(struct i2c_client *client)
205205

206206
charger->charge_gpiod = devm_gpiod_get_optional(&client->dev,
207207
NULL, GPIOD_IN);
208-
if (IS_ERR(charger->charge_gpiod))
209-
return dev_err_probe(&client->dev,
208+
if (IS_ERR(charger->charge_gpiod)) {
209+
ret = dev_err_probe(&client->dev,
210210
PTR_ERR(charger->charge_gpiod),
211211
"failed to get charge GPIO\n");
212+
goto err;
213+
}
212214

213215
if (charger->charge_gpiod) {
214216
gpiod_set_consumer_name(charger->charge_gpiod, "BATT CHRG");

0 commit comments

Comments
 (0)