* [PATCH] power: supply: z2_battery: Fix possible memleak in z2_batt_probe()
@ 2022-11-21 1:18 Zhang Qilong
2022-11-22 20:33 ` Linus Walleij
0 siblings, 1 reply; 3+ messages in thread
From: Zhang Qilong @ 2022-11-21 1:18 UTC (permalink / raw)
To: sre, linus.walleij, daniel; +Cc: linux-pm
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 <zhangqilong3@huawei.com>
---
drivers/power/supply/z2_battery.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/power/supply/z2_battery.c b/drivers/power/supply/z2_battery.c
index 1897c2984860..d033c1d3ee42 100644
--- a/drivers/power/supply/z2_battery.c
+++ b/drivers/power/supply/z2_battery.c
@@ -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");
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: z2_battery: Fix possible memleak in z2_batt_probe()
2022-11-21 1:18 [PATCH] power: supply: z2_battery: Fix possible memleak in z2_batt_probe() Zhang Qilong
@ 2022-11-22 20:33 ` Linus Walleij
2022-11-24 21:58 ` Sebastian Reichel
0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2022-11-22 20:33 UTC (permalink / raw)
To: Zhang Qilong; +Cc: sre, daniel, linux-pm
On Mon, Nov 21, 2022 at 2:14 AM Zhang Qilong <zhangqilong3@huawei.com> wrote:
> 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 <zhangqilong3@huawei.com>
Oops good catch!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: z2_battery: Fix possible memleak in z2_batt_probe()
2022-11-22 20:33 ` Linus Walleij
@ 2022-11-24 21:58 ` Sebastian Reichel
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2022-11-24 21:58 UTC (permalink / raw)
To: Linus Walleij; +Cc: Zhang Qilong, daniel, linux-pm
[-- Attachment #1: Type: text/plain, Size: 605 bytes --]
Hi,
On Tue, Nov 22, 2022 at 09:33:34PM +0100, Linus Walleij wrote:
> On Mon, Nov 21, 2022 at 2:14 AM Zhang Qilong <zhangqilong3@huawei.com> wrote:
>
> > 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 <zhangqilong3@huawei.com>
>
> Oops good catch!
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Thanks, queued.
-- Sebastian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-24 21:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 1:18 [PATCH] power: supply: z2_battery: Fix possible memleak in z2_batt_probe() Zhang Qilong
2022-11-22 20:33 ` Linus Walleij
2022-11-24 21:58 ` Sebastian Reichel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.