mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [patch 1/3] remoteproc: memory leak in rproc_handle_carveout()
@ 2012-09-25  7:01 Dan Carpenter
  2012-09-30  9:28 ` Ohad Ben-Cohen
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2012-09-25  7:01 UTC (permalink / raw)
  To: Ohad Ben-Cohen; +Cc: linux-kernel, kernel-janitors

We only need to allocate mapping if there is an rproc domain.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Static checker stuff.  Handle with appropriate caution.

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index b6c6229..f163704 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -573,17 +573,10 @@ static int rproc_handle_carveout(struct rproc *rproc,
 	dev_dbg(dev, "carveout rsc: da %x, pa %x, len %x, flags %x\n",
 			rsc->da, rsc->pa, rsc->len, rsc->flags);
 
-	mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
-	if (!mapping) {
-		dev_err(dev, "kzalloc mapping failed\n");
-		return -ENOMEM;
-	}
-
 	carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
 	if (!carveout) {
 		dev_err(dev, "kzalloc carveout failed\n");
-		ret = -ENOMEM;
-		goto free_mapping;
+		return -ENOMEM;
 	}
 
 	va = dma_alloc_coherent(dev->parent, rsc->len, &dma, GFP_KERNEL);
@@ -613,11 +606,18 @@ static int rproc_handle_carveout(struct rproc *rproc,
 	 * physical address in this case.
 	 */
 	if (rproc->domain) {
+		mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
+		if (!mapping) {
+			dev_err(dev, "kzalloc mapping failed\n");
+			ret = -ENOMEM;
+			goto dma_free;
+		}
+
 		ret = iommu_map(rproc->domain, rsc->da, dma, rsc->len,
 								rsc->flags);
 		if (ret) {
 			dev_err(dev, "iommu_map failed: %d\n", ret);
-			goto dma_free;
+			goto free_mapping;
 		}
 
 		/*
@@ -662,12 +662,12 @@ static int rproc_handle_carveout(struct rproc *rproc,
 
 	return 0;
 
+free_mapping:
+	kfree(mapping);
 dma_free:
 	dma_free_coherent(dev->parent, rsc->len, va, dma);
 free_carv:
 	kfree(carveout);
-free_mapping:
-	kfree(mapping);
 	return ret;
 }
 

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

* Re: [patch 1/3] remoteproc: memory leak in rproc_handle_carveout()
  2012-09-25  7:01 [patch 1/3] remoteproc: memory leak in rproc_handle_carveout() Dan Carpenter
@ 2012-09-30  9:28 ` Ohad Ben-Cohen
  0 siblings, 0 replies; 2+ messages in thread
From: Ohad Ben-Cohen @ 2012-09-30  9:28 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-kernel, kernel-janitors

On Tue, Sep 25, 2012 at 9:01 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> We only need to allocate mapping if there is an rproc domain.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Static checker stuff.  Handle with appropriate caution.

Applied, thanks.

I'm just changing the subject, because this actually fixes a sneaky
NULL-dereference and not a memory leak.

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

end of thread, other threads:[~2012-09-30  9:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-25  7:01 [patch 1/3] remoteproc: memory leak in rproc_handle_carveout() Dan Carpenter
2012-09-30  9:28 ` Ohad Ben-Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®