Commit a72fe8eb authored by Zhang Qilong's avatar Zhang Qilong Committed by Greg Kroah-Hartman
Browse files

power: supply: z2_battery: Fix possible memleak in z2_batt_probe()



[ Upstream commit 955bee20 ]

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: a3b4388e ("power: supply: z2_battery: Convert to GPIO descriptors")
Signed-off-by: default avatarZhang Qilong <zhangqilong3@huawei.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 5ba0e8fa
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -206,10 +206,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");