All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] arch/mips/txx9: introduce missing kfree, iounmap
@ 2009-09-11 16:21 ` Julia Lawall
  0 siblings, 0 replies; 26+ messages in thread
From: Julia Lawall @ 2009-09-11 16:21 UTC (permalink / raw)
  To: Ralf Baechle, linux-mips, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

Error handling code following a kzalloc should free the allocated data.
Error handling code following an ioremap should iounmap the allocated data.

The semantic match that finds the first problem is as follows:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@r exists@
local idexpression x;
statement S;
expression E;
identifier f,f1,l;
position p1,p2;
expression *ptr != NULL;
@@

x@p1 = \(kmalloc\|kzalloc\|kcalloc\)(...);
...
if (x == NULL) S
<... when != x
     when != if (...) { <+...x...+> }
(
x->f1 = E
|
 (x->f1 == NULL || ...)
|
 f(...,x->f1,...)
)
...>
(
 return \(0\|<+...x...+>\|ptr\);
|
 return@p2 ...;
)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@

print "* file: %s kmalloc %s return %s" % (p1[0].file,p1[0].line,p2[0].line)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
---
 arch/mips/txx9/generic/setup.c      |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c
index a205e2b..5744af2 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -781,8 +781,10 @@ void __init txx9_iocled_init(unsigned long baseaddr,
 	if (!iocled)
 		return;
 	iocled->mmioaddr = ioremap(baseaddr, 1);
-	if (!iocled->mmioaddr)
+	if (!iocled->mmioaddr) {
+		kfree(iocled);
 		return;
+	}
 	iocled->chip.get = txx9_iocled_get;
 	iocled->chip.set = txx9_iocled_set;
 	iocled->chip.direction_input = txx9_iocled_dir_in;
@@ -790,8 +792,11 @@ void __init txx9_iocled_init(unsigned long baseaddr,
 	iocled->chip.label = "iocled";
 	iocled->chip.base = basenum;
 	iocled->chip.ngpio = num;
-	if (gpiochip_add(&iocled->chip))
+	if (gpiochip_add(&iocled->chip)) {
+		iounmap(iocled->mmioaddr);
+		kfree(iocled);
 		return;
+	}
 	if (basenum < 0)
 		basenum = iocled->chip.base;
 

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

end of thread, other threads:[~2009-09-15 15:56 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-11 16:21 [PATCH 1/8] arch/mips/txx9: introduce missing kfree, iounmap Julia Lawall
2009-09-11 16:21 ` Julia Lawall
2009-09-13 14:25 ` Atsushi Nemoto
2009-09-13 14:25   ` Atsushi Nemoto
2009-09-13 15:14   ` Julia Lawall
2009-09-13 15:14     ` Julia Lawall
2009-09-13 15:33     ` Atsushi Nemoto
2009-09-13 15:33       ` Atsushi Nemoto
2009-09-13 15:49       ` Julia Lawall
2009-09-13 15:49         ` Julia Lawall
2009-09-13 19:15       ` Julia Lawall
2009-09-13 19:15         ` Julia Lawall
2009-09-14 14:56         ` Ralf Baechle
2009-09-14 14:56           ` Ralf Baechle
2009-09-15  5:03         ` Julia Lawall
2009-09-15  5:03           ` Julia Lawall
2009-09-15 15:45           ` Atsushi Nemoto
2009-09-15 15:45             ` Atsushi Nemoto
2009-09-15 15:47             ` Julia Lawall
2009-09-15 15:47               ` Julia Lawall
2009-09-15 15:56             ` Julia Lawall
2009-09-15 15:56               ` Julia Lawall
2009-09-15 14:02         ` Ralf Rösch
2009-09-15 14:02           ` Ralf Rösch
2009-09-15 14:35           ` Julia Lawall
2009-09-15 14:35             ` Julia Lawall

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.