kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
@ 2021-09-04 11:37 Christophe JAILLET
  2021-09-09 18:01 ` Mathieu Poirier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-09-04 11:37 UTC (permalink / raw)
  To: ohad, bjorn.andersson, mathieu.poirier, james.quinlan
  Cc: linux-remoteproc, linux-kernel, kernel-janitors, Christophe JAILLET

If 'copy_dma_range_map() fails, the memory allocated for 'rvdev' will leak.
Move the 'copy_dma_range_map()' call after the device registration so
that 'rproc_rvdev_release()' can be called to free some resources.

Also, branch to the error handling path if 'copy_dma_range_map()' instead
of a direct return to avoid some other leaks.

Fixes: e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.
Review with care. I don't like to move code around because of possible
side-effect.
---
 drivers/remoteproc/remoteproc_core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 502b6604b757..775df165eb45 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -556,9 +556,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
 	/* Initialise vdev subdevice */
 	snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index);
 	rvdev->dev.parent = &rproc->dev;
-	ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
-	if (ret)
-		return ret;
 	rvdev->dev.release = rproc_rvdev_release;
 	dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name);
 	dev_set_drvdata(&rvdev->dev, rvdev);
@@ -568,6 +565,11 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
 		put_device(&rvdev->dev);
 		return ret;
 	}
+
+	ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
+	if (ret)
+		goto free_rvdev;
+
 	/* Make device dma capable by inheriting from parent's capabilities */
 	set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent));
 
-- 
2.30.2


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

* Re: [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
  2021-09-04 11:37 [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()' Christophe JAILLET
@ 2021-09-09 18:01 ` Mathieu Poirier
  2021-09-09 20:23 ` Jim Quinlan
  2021-10-15 17:22 ` (subset) " Bjorn Andersson
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Poirier @ 2021-09-09 18:01 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: ohad, bjorn.andersson, james.quinlan, linux-remoteproc,
	linux-kernel, kernel-janitors

On Sat, Sep 04, 2021 at 01:37:32PM +0200, Christophe JAILLET wrote:
> If 'copy_dma_range_map() fails, the memory allocated for 'rvdev' will leak.
> Move the 'copy_dma_range_map()' call after the device registration so
> that 'rproc_rvdev_release()' can be called to free some resources.
> 
> Also, branch to the error handling path if 'copy_dma_range_map()' instead
> of a direct return to avoid some other leaks.
> 
> Fixes: e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
> Review with care. I don't like to move code around because of possible
> side-effect.
> ---
>  drivers/remoteproc/remoteproc_core.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 502b6604b757..775df165eb45 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -556,9 +556,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>  	/* Initialise vdev subdevice */
>  	snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index);
>  	rvdev->dev.parent = &rproc->dev;
> -	ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
> -	if (ret)
> -		return ret;
>  	rvdev->dev.release = rproc_rvdev_release;
>  	dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name);
>  	dev_set_drvdata(&rvdev->dev, rvdev);
> @@ -568,6 +565,11 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>  		put_device(&rvdev->dev);
>  		return ret;
>  	}
> +
> +	ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
> +	if (ret)
> +		goto free_rvdev;
> +

Good catch.

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  	/* Make device dma capable by inheriting from parent's capabilities */
>  	set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent));
>  
> -- 
> 2.30.2
> 

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

* Re: [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
  2021-09-04 11:37 [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()' Christophe JAILLET
  2021-09-09 18:01 ` Mathieu Poirier
@ 2021-09-09 20:23 ` Jim Quinlan
  2021-10-15 17:22 ` (subset) " Bjorn Andersson
  2 siblings, 0 replies; 4+ messages in thread
From: Jim Quinlan @ 2021-09-09 20:23 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Ohad Ben-Cohen, Bjorn Andersson, Mathieu Poirier,
	open list:REMOTE PROCESSOR REMOTEPROC SUBSYSTEM, open list,
	kernel-janitors

On Sat, Sep 4, 2021 at 7:37 AM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> If 'copy_dma_range_map() fails, the memory allocated for 'rvdev' will leak.
> Move the 'copy_dma_range_map()' call after the device registration so
> that 'rproc_rvdev_release()' can be called to free some resources.
>
> Also, branch to the error handling path if 'copy_dma_range_map()' instead
> of a direct return to avoid some other leaks.
>
> Fixes: e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only.
> Review with care. I don't like to move code around because of possible
> side-effect.
> ---
>  drivers/remoteproc/remoteproc_core.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 502b6604b757..775df165eb45 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -556,9 +556,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>         /* Initialise vdev subdevice */
>         snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index);
>         rvdev->dev.parent = &rproc->dev;
> -       ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
> -       if (ret)
> -               return ret;
>         rvdev->dev.release = rproc_rvdev_release;
>         dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name);
>         dev_set_drvdata(&rvdev->dev, rvdev);
> @@ -568,6 +565,11 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>                 put_device(&rvdev->dev);
>                 return ret;
>         }
> +
> +       ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
> +       if (ret)
> +               goto free_rvdev;
> +
LGTM, thanks.
Reviewed-by: Jim Quinlan <james.quinlan@broadcom.com>

>         /* Make device dma capable by inheriting from parent's capabilities */
>         set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent));
>
> --
> 2.30.2
>

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

* Re: (subset) [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
  2021-09-04 11:37 [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()' Christophe JAILLET
  2021-09-09 18:01 ` Mathieu Poirier
  2021-09-09 20:23 ` Jim Quinlan
@ 2021-10-15 17:22 ` Bjorn Andersson
  2 siblings, 0 replies; 4+ messages in thread
From: Bjorn Andersson @ 2021-10-15 17:22 UTC (permalink / raw)
  To: mathieu.poirier, james.quinlan, Christophe JAILLET, ohad
  Cc: kernel-janitors, linux-remoteproc, linux-kernel

On Sat, 4 Sep 2021 13:37:32 +0200, Christophe JAILLET wrote:
> If 'copy_dma_range_map() fails, the memory allocated for 'rvdev' will leak.
> Move the 'copy_dma_range_map()' call after the device registration so
> that 'rproc_rvdev_release()' can be called to free some resources.
> 
> Also, branch to the error handling path if 'copy_dma_range_map()' instead
> of a direct return to avoid some other leaks.
> 
> [...]

Applied, thanks!

[1/1] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()'
      commit: 0374a4ea7269645c46c3eb288526ea072fa19e79

Best regards,
-- 
Bjorn Andersson <bjorn.andersson@linaro.org>

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

end of thread, other threads:[~2021-10-15 17:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04 11:37 [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()' Christophe JAILLET
2021-09-09 18:01 ` Mathieu Poirier
2021-09-09 20:23 ` Jim Quinlan
2021-10-15 17:22 ` (subset) " Bjorn Andersson

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