All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init
@ 2022-01-24 13:13 Miaoqian Lin
  2022-02-11 20:04 ` Sebastian Reichel
  0 siblings, 1 reply; 3+ messages in thread
From: Miaoqian Lin @ 2022-01-24 13:13 UTC (permalink / raw)
  To: Sebastian Reichel, 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 memory leak by calling kobject_put().

Fixes: 8c0984e5a753 ("power: move power supply drivers to power/supply")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/power/supply/ab8500_fg.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index 05fe9724ba50..57799a8079d4 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -2545,8 +2545,10 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di)
 	ret = kobject_init_and_add(&di->fg_kobject,
 		&ab8500_fg_ktype,
 		NULL, "battery");
-	if (ret < 0)
+	if (ret < 0) {
+		kobject_put(&di->fg_kobject);
 		dev_err(di->dev, "failed to create sysfs entry\n");
+	}
 
 	return ret;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init
  2022-01-24 13:13 [PATCH] power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init Miaoqian Lin
@ 2022-02-11 20:04 ` Sebastian Reichel
  2022-02-11 21:32   ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Reichel @ 2022-02-11 20:04 UTC (permalink / raw)
  To: Miaoqian Lin; +Cc: linux-pm, linux-kernel, Linus Walleij

[-- Attachment #1: Type: text/plain, Size: 1527 bytes --]

[+cc Linus Walleij]

Hi,

On Mon, Jan 24, 2022 at 01:13:46PM +0000, Miaoqian Lin 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 memory leak by calling kobject_put().
> 
> Fixes: 8c0984e5a753 ("power: move power supply drivers to power/supply")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---

Thanks, queued power-supply's for-next branch.

Linus, if I'm not mistaken the custom sysfs ABI (i.e. everything related
to ab8500_fg_sysfs_init() can just be removed since the same thing is
already exposed standardized via POWER_SUPPLY_PROP_CHARGE_FULL and
POWER_SUPPLY_PROP_CHARGE_NOW?

-- Sebastian

>  drivers/power/supply/ab8500_fg.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
> index 05fe9724ba50..57799a8079d4 100644
> --- a/drivers/power/supply/ab8500_fg.c
> +++ b/drivers/power/supply/ab8500_fg.c
> @@ -2545,8 +2545,10 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di)
>  	ret = kobject_init_and_add(&di->fg_kobject,
>  		&ab8500_fg_ktype,
>  		NULL, "battery");
> -	if (ret < 0)
> +	if (ret < 0) {
> +		kobject_put(&di->fg_kobject);
>  		dev_err(di->dev, "failed to create sysfs entry\n");
> +	}
>  
>  	return ret;
>  }
> -- 
> 2.17.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init
  2022-02-11 20:04 ` Sebastian Reichel
@ 2022-02-11 21:32   ` Linus Walleij
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2022-02-11 21:32 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: Miaoqian Lin, linux-pm, linux-kernel

On Fri, Feb 11, 2022 at 9:04 PM Sebastian Reichel
<sebastian.reichel@collabora.com> wrote:

> > Fixes: 8c0984e5a753 ("power: move power supply drivers to power/supply")
> > Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> > ---
>
> Thanks, queued power-supply's for-next branch.
>
> Linus, if I'm not mistaken the custom sysfs ABI (i.e. everything related
> to ab8500_fg_sysfs_init() can just be removed since the same thing is
> already exposed standardized via POWER_SUPPLY_PROP_CHARGE_FULL and
> POWER_SUPPLY_PROP_CHARGE_NOW?

Yes, I delete other weird custom sysfs, so I'll cook a patch to
get rid of this too.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-11 21:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 13:13 [PATCH] power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init Miaoqian Lin
2022-02-11 20:04 ` Sebastian Reichel
2022-02-11 21:32   ` 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.