linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvmem: core: Prevent memory leak when device is unregistered
@ 2017-05-15 11:13 Mika Westerberg
  2017-05-15 12:48 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mika Westerberg @ 2017-05-15 11:13 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: Mika Westerberg, linux-kernel

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

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

* Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered
  2017-05-15 11:13 [PATCH] nvmem: core: Prevent memory leak when device is unregistered Mika Westerberg
@ 2017-05-15 12:48 ` Andy Shevchenko
  2017-05-16 13:45 ` Johan Hovold
  2017-05-16 21:33 ` Andrey Smirnov
  2 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2017-05-15 12:48 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Srinivas Kandagatla, linux-kernel

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

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

* Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered
  2017-05-15 11:13 [PATCH] nvmem: core: Prevent memory leak when device is unregistered Mika Westerberg
  2017-05-15 12:48 ` Andy Shevchenko
@ 2017-05-16 13:45 ` Johan Hovold
  2017-05-16 21:33 ` Andrey Smirnov
  2 siblings, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2017-05-16 13:45 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Srinivas Kandagatla, linux-kernel

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

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

* Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered
  2017-05-15 11:13 [PATCH] nvmem: core: Prevent memory leak when device is unregistered Mika Westerberg
  2017-05-15 12:48 ` Andy Shevchenko
  2017-05-16 13:45 ` Johan Hovold
@ 2017-05-16 21:33 ` Andrey Smirnov
  2017-05-17  9:10   ` Mika Westerberg
  2 siblings, 1 reply; 5+ messages in thread
From: Andrey Smirnov @ 2017-05-16 21:33 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: Srinivas Kandagatla, linux-kernel

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
>

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

* Re: [PATCH] nvmem: core: Prevent memory leak when device is unregistered
  2017-05-16 21:33 ` Andrey Smirnov
@ 2017-05-17  9:10   ` Mika Westerberg
  0 siblings, 0 replies; 5+ messages in thread
From: Mika Westerberg @ 2017-05-17  9:10 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: Srinivas Kandagatla, linux-kernel

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 :)

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

end of thread, other threads:[~2017-05-17  9:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-15 11:13 [PATCH] nvmem: core: Prevent memory leak when device is unregistered Mika Westerberg
2017-05-15 12:48 ` Andy Shevchenko
2017-05-16 13:45 ` Johan Hovold
2017-05-16 21:33 ` Andrey Smirnov
2017-05-17  9:10   ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).