linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] misc: fastrpc: fix memory leak
@ 2019-07-04 16:25 Jorge Ramirez-Ortiz
  0 siblings, 0 replies; 4+ messages in thread
From: Jorge Ramirez-Ortiz @ 2019-07-04 16:25 UTC (permalink / raw)
  To: jorge.ramirez-ortiz, arnd, gregkh; +Cc: linux-kernel

Deallocate the buffer when no longer required.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
---
 drivers/misc/fastrpc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 98603e235cf0..af8fd2101a1d 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -279,8 +279,10 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev,
 
 	buf->virt = dma_alloc_coherent(dev, buf->size, (dma_addr_t *)&buf->phys,
 				       GFP_KERNEL);
-	if (!buf->virt)
+	if (!buf->virt) {
+		kfree(buf);
 		return -ENOMEM;
+	}
 
 	if (fl->sctx && fl->sctx->sid)
 		buf->phys += ((u64)fl->sctx->sid << 32);
-- 
2.21.0


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

* Re: [PATCH] misc: fastrpc: fix memory leak
  2020-04-29 15:29 Srinivas Kandagatla
@ 2020-04-30  5:02 ` Bjorn Andersson
  0 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2020-04-30  5:02 UTC (permalink / raw)
  To: Srinivas Kandagatla; +Cc: gregkh, linux-arm-msm, linux-kernel, arnd

On Wed 29 Apr 08:29 PDT 2020, Srinivas Kandagatla wrote:

> if misc_register() fails, previously allocated data is left without freeing,
> this could result in memory leak.

s/could/will/

> 
> So fix it!
> 

As Markus pointed out, a Fixes: tag would be in order to make sure this
is backported properly.


PS: although unlikely, if of_platform_populate() where to fail we're
leaking both the contet and the misc device.

Regards,
Bjorn

> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
> ---
>  drivers/misc/fastrpc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
> index e3e085e33d46..9065d3e71ff7 100644
> --- a/drivers/misc/fastrpc.c
> +++ b/drivers/misc/fastrpc.c
> @@ -1613,8 +1613,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
>  					    domains[domain_id]);
>  	data->miscdev.fops = &fastrpc_fops;
>  	err = misc_register(&data->miscdev);
> -	if (err)
> +	if (err) {
> +		kfree(data);
>  		return err;
> +	}
>  
>  	kref_init(&data->refcount);
>  
> -- 
> 2.21.0
> 

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

* Re: [PATCH] misc: fastrpc: fix memory leak
@ 2020-04-29 20:40 Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2020-04-29 20:40 UTC (permalink / raw)
  To: Srinivas Kandagatla, linux-arm-msm
  Cc: linux-kernel, kernel-janitors, Arnd Bergmann, Greg Kroah-Hartman

> if misc_register() fails, previously allocated data is left without freeing,
> this could result in memory leak.

How do you think about a wording variant like the following?

   Subject:
   [PATCH v2] misc: fastrpc: Fix an incomplete memory release in fastrpc_rpmsg_probe()

   Change description:
   A few fastrpc data were not released after a call of the
   function “misc_register” failed.
   Thus add a call of the function “kfree”.


> So fix it!

Would you like to replace such an information by the tag “Fixes”?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=96c9a7802af7d500a582d89a8b864584fe878c1b#n183

Regards,
Markus

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

* [PATCH] misc: fastrpc: fix memory leak
@ 2020-04-29 15:29 Srinivas Kandagatla
  2020-04-30  5:02 ` Bjorn Andersson
  0 siblings, 1 reply; 4+ messages in thread
From: Srinivas Kandagatla @ 2020-04-29 15:29 UTC (permalink / raw)
  To: gregkh; +Cc: linux-arm-msm, linux-kernel, arnd, Srinivas Kandagatla

if misc_register() fails, previously allocated data is left without freeing,
this could result in memory leak.

So fix it!

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/misc/fastrpc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index e3e085e33d46..9065d3e71ff7 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -1613,8 +1613,10 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
 					    domains[domain_id]);
 	data->miscdev.fops = &fastrpc_fops;
 	err = misc_register(&data->miscdev);
-	if (err)
+	if (err) {
+		kfree(data);
 		return err;
+	}
 
 	kref_init(&data->refcount);
 
-- 
2.21.0


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

end of thread, other threads:[~2020-04-30  5:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04 16:25 [PATCH] misc: fastrpc: fix memory leak Jorge Ramirez-Ortiz
2020-04-29 15:29 Srinivas Kandagatla
2020-04-30  5:02 ` Bjorn Andersson
2020-04-29 20:40 Markus Elfring

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