* [PATCH] power: supply: ab8500: Fix memory leak in ab8500_chargalg_sysfs_init
@ 2022-01-28 17:33 Miaoqian Lin
2022-01-29 0:53 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2022-01-28 17:33 UTC (permalink / raw)
To: Sebastian Reichel, Linus Walleij, linux-pm, linux-kernel; +Cc: linmq006
kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add()
If this function returns an error, kobject_put() must be called to
properly clean up the memory associated with the object.
Fix this issue by adding kobject_put().
Fixes: c5b64a990e7f ("power: supply: ab8500: Rename charging algorithm symbols")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/power/supply/ab8500_chargalg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c
index c4a2fe07126c..658139797509 100644
--- a/drivers/power/supply/ab8500_chargalg.c
+++ b/drivers/power/supply/ab8500_chargalg.c
@@ -1907,8 +1907,10 @@ static int ab8500_chargalg_sysfs_init(struct ab8500_chargalg *di)
ret = kobject_init_and_add(&di->chargalg_kobject,
&ab8500_chargalg_ktype,
NULL, "ab8500_chargalg");
- if (ret < 0)
+ if (ret < 0) {
dev_err(di->dev, "failed to create sysfs entry\n");
+ kobject_put(&di->chargalg_kobject);
+ }
return ret;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: ab8500: Fix memory leak in ab8500_chargalg_sysfs_init
2022-01-28 17:33 [PATCH] power: supply: ab8500: Fix memory leak in ab8500_chargalg_sysfs_init Miaoqian Lin
@ 2022-01-29 0:53 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2022-01-29 0:53 UTC (permalink / raw)
To: Miaoqian Lin; +Cc: Sebastian Reichel, linux-pm, linux-kernel
On Fri, Jan 28, 2022 at 6:33 PM Miaoqian Lin <linmq006@gmail.com> wrote:
> kobject_init_and_add() takes reference even when it fails.
> According to the doc of kobject_init_and_add()
>
> If this function returns an error, kobject_put() must be called to
> properly clean up the memory associated with the object.
>
> Fix this issue by adding kobject_put().
>
> Fixes: c5b64a990e7f ("power: supply: ab8500: Rename charging algorithm symbols")
Really? I think this code is older.
> @@ -1907,8 +1907,10 @@ static int ab8500_chargalg_sysfs_init(struct ab8500_chargalg *di)
> ret = kobject_init_and_add(&di->chargalg_kobject,
> &ab8500_chargalg_ktype,
> NULL, "ab8500_chargalg");
> - if (ret < 0)
> + if (ret < 0) {
> dev_err(di->dev, "failed to create sysfs entry\n");
> + kobject_put(&di->chargalg_kobject);
> + }
I wouldn't bother with this.
This code is getting deleted in this patch:
https://lore.kernel.org/linux-pm/20220129004925.639684-10-linus.walleij@linaro.org/T/#u
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-29 0:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-28 17:33 [PATCH] power: supply: ab8500: Fix memory leak in ab8500_chargalg_sysfs_init Miaoqian Lin
2022-01-29 0:53 ` Linus Walleij
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.