mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mfd: Fix memory leak in mfd_add_devices()
@ 2013-10-29 14:47 Geert Uytterhoeven
  2013-12-04  8:30 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Uytterhoeven @ 2013-10-29 14:47 UTC (permalink / raw)
  To: Andres Salomon, Samuel Ortiz, Lee Jones; +Cc: linux-kernel, Geert Uytterhoeven

If the first call to mfd_add_device() fails, no child devices have been
registered to the parent yet, and thus mfd_remove_devices() won't find
anything to remove nor free.
Hence the previously allocated array of atomic_t objects will leak.

Free the array instead of calling mfd_remove_devices() on failure during
the first loop iteration to fix this.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
 drivers/mfd/mfd-core.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 8736f4539bc0..968775da638a 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -187,7 +187,7 @@ int mfd_add_devices(struct device *parent, int id,
 		    int irq_base, struct irq_domain *domain)
 {
 	int i;
-	int ret = 0;
+	int ret;
 	atomic_t *cnts;
 
 	/* initialize reference counting for all cells */
@@ -200,12 +200,16 @@ int mfd_add_devices(struct device *parent, int id,
 		ret = mfd_add_device(parent, id, cells + i, cnts + i, mem_base,
 				     irq_base, domain);
 		if (ret)
-			break;
+			goto fail;
 	}
 
-	if (ret)
-		mfd_remove_devices(parent);
+	return 0;
 
+fail:
+	if (i)
+		mfd_remove_devices(parent);
+	else
+		kfree(cnts);
 	return ret;
 }
 EXPORT_SYMBOL(mfd_add_devices);
-- 
1.7.9.5


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

end of thread, other threads:[~2013-12-04  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-29 14:47 [PATCH] mfd: Fix memory leak in mfd_add_devices() Geert Uytterhoeven
2013-12-04  8:30 ` Lee Jones

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®