From: Julia Lawall <julia@diku.dk> To: Ralf Baechle <ralf@linux-mips.org>, linux-mips@linux-mips.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/8] arch/mips/txx9: introduce missing kfree, iounmap Date: Fri, 11 Sep 2009 18:21:00 +0200 (CEST) [thread overview] Message-ID: <Pine.LNX.4.64.0909111820370.10552@pc-004.diku.dk> (raw) 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;
WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia@diku.dk> To: Ralf Baechle <ralf@linux-mips.org>, linux-mips@linux-mips.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH 1/8] arch/mips/txx9: introduce missing kfree, iounmap Date: Fri, 11 Sep 2009 16:21:00 +0000 [thread overview] Message-ID: <Pine.LNX.4.64.0909111820370.10552@pc-004.diku.dk> (raw) 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;
next reply other threads:[~2009-09-11 16:21 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-09-11 16:21 Julia Lawall [this message] 2009-09-11 16:21 ` [PATCH 1/8] arch/mips/txx9: introduce missing kfree, iounmap 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=Pine.LNX.4.64.0909111820370.10552@pc-004.diku.dk \ --to=julia@diku.dk \ --cc=kernel-janitors@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mips@linux-mips.org \ --cc=ralf@linux-mips.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.