Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1641560 > unrolled thread

[PATCH] nvmem: core: Prevent memory leak when device is unregistered

Started byMika Westerberg <mika.westerberg@linux.intel.com>
First post2017-05-15 13:20 +0200
Last post2017-05-17 11:20 +0200
Articles 5 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] nvmem: core: Prevent memory leak when device is unregistered Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-05-15 13:20 +0200
    Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-05-15 14:50 +0200
    Re: [PATCH] nvmem: core: Prevent memory leak when device is  unregistered Johan Hovold <johan@kernel.org> - 2017-05-16 15:50 +0200
    Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered Andrey Smirnov <andrew.smirnov@gmail.com> - 2017-05-16 23:40 +0200
      Re: [PATCH] nvmem: core: Prevent memory leak when device is  unregistered Mika Westerberg <mika.westerberg@linux.intel.com> - 2017-05-17 11:20 +0200

#1641560 — [PATCH] nvmem: core: Prevent memory leak when device is unregistered

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2017-05-15 13:20 +0200
Subject[PATCH] nvmem: core: Prevent memory leak when device is unregistered
Message-ID<tHmcG-7ob-19@gated-at.bofh.it>
The nvmem_unregister() calls device_del() for the device but forgets to
call put_device() to actually release the device object which causes
that memory to be leaked.

Fix this by calling device_unregister() for the device intead which also
calls put_device() for the device releasing it eventually.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 8c830a80a648..112c8072e0f3 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)
 		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
 
 	nvmem_device_remove_all_cells(nvmem);
-	device_del(&nvmem->dev);
+	device_unregister(&nvmem->dev);
 
 	return 0;
 }
-- 
2.11.0

[toc] | [next] | [standalone]


#1641624

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-05-15 14:50 +0200
Message-ID<tHnBL-8iJ-3@gated-at.bofh.it>
In reply to#1641560
On Mon, May 15, 2017 at 2:13 PM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
> The nvmem_unregister() calls device_del() for the device but forgets to
> call put_device() to actually release the device object which causes
> that memory to be leaked.
>
> Fix this by calling device_unregister() for the device intead which also

instead

> calls put_device() for the device releasing it eventually.
>

Other than that, FWIW:
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
>  drivers/nvmem/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 8c830a80a648..112c8072e0f3 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)
>                 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
>
>         nvmem_device_remove_all_cells(nvmem);
> -       device_del(&nvmem->dev);
> +       device_unregister(&nvmem->dev);
>
>         return 0;
>  }
> --
> 2.11.0
>



-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [next] | [standalone]


#1642569 — Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered

FromJohan Hovold <johan@kernel.org>
Date2017-05-16 15:50 +0200
SubjectRe: [PATCH] nvmem: core: Prevent memory leak when device is unregistered
Message-ID<tHL1n-6fA-13@gated-at.bofh.it>
In reply to#1641560
On Mon, May 15, 2017 at 02:13:23PM +0300, Mika Westerberg wrote:
> The nvmem_unregister() calls device_del() for the device but forgets to
> call put_device() to actually release the device object which causes
> that memory to be leaked.
> 
> Fix this by calling device_unregister() for the device intead which also
> calls put_device() for the device releasing it eventually.

I was gonna suggest that you fix up the related leaks in the
registration error paths as well, but since they are really distinct I
just submitted a patch to fix those up separately instead (kfree was
being just instead of put_device and the device was never deregistered
on late probe errors).

> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---
>  drivers/nvmem/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 8c830a80a648..112c8072e0f3 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)
>  		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
>  
>  	nvmem_device_remove_all_cells(nvmem);
> -	device_del(&nvmem->dev);
> +	device_unregister(&nvmem->dev);

Might be cleaner to use an explicit call to put_device() here since the
driver currently does not use device_register().

>  
>  	return 0;
>  }

Thanks,
Johan

[toc] | [prev] | [next] | [standalone]


#1642842

FromAndrey Smirnov <andrew.smirnov@gmail.com>
Date2017-05-16 23:40 +0200
Message-ID<tHSme-2zE-19@gated-at.bofh.it>
In reply to#1641560
On Mon, May 15, 2017 at 4:13 AM, Mika Westerberg
<mika.westerberg@linux.intel.com> wrote:
> The nvmem_unregister() calls device_del() for the device but forgets to
> call put_device() to actually release the device object which causes
> that memory to be leaked.
>
> Fix this by calling device_unregister() for the device intead which also
> calls put_device() for the device releasing it eventually.
>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> ---

FWIW, I submitted similar fix for this here:

lkml.kernel.org/r/20170418142454.23921-2-andrew.smirnov@gmail.com

>  drivers/nvmem/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 8c830a80a648..112c8072e0f3 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -528,7 +528,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)
>                 device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
>
>         nvmem_device_remove_all_cells(nvmem);
> -       device_del(&nvmem->dev);
> +       device_unregister(&nvmem->dev);
>
>         return 0;
>  }
> --
> 2.11.0
>

[toc] | [prev] | [next] | [standalone]


#1643166 — Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered

FromMika Westerberg <mika.westerberg@linux.intel.com>
Date2017-05-17 11:20 +0200
SubjectRe: [PATCH] nvmem: core: Prevent memory leak when device is unregistered
Message-ID<tI3hE-1cV-17@gated-at.bofh.it>
In reply to#1642842
On Tue, May 16, 2017 at 02:33:55PM -0700, Andrey Smirnov wrote:
> On Mon, May 15, 2017 at 4:13 AM, Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> > The nvmem_unregister() calls device_del() for the device but forgets to
> > call put_device() to actually release the device object which causes
> > that memory to be leaked.
> >
> > Fix this by calling device_unregister() for the device intead which also
> > calls put_device() for the device releasing it eventually.
> >
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > ---
> 
> FWIW, I submitted similar fix for this here:
> 
> lkml.kernel.org/r/20170418142454.23921-2-andrew.smirnov@gmail.com

Cool, let's go with that one instead then :)

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web