diff options
author | Julia Lawall <julia@diku.dk> | 2009-09-13 15:15:18 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2009-09-17 14:07:43 -0400 |
commit | 70ebadc8e30efef3bf21ba94b3571537de8bcf4e (patch) | |
tree | 313727133efb7ea0881d2a78e8f1b83820ce3593 /arch/mips | |
parent | 13680ade4e57090a8ccad332e84e1f3d48b67125 (diff) |
MIPS: TXx9: Fix error handling.
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>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/txx9/generic/setup.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c index a205e2ba8e7b..c860810722c0 100644 --- a/arch/mips/txx9/generic/setup.c +++ b/arch/mips/txx9/generic/setup.c | |||
@@ -782,7 +782,7 @@ void __init txx9_iocled_init(unsigned long baseaddr, | |||
782 | return; | 782 | return; |
783 | iocled->mmioaddr = ioremap(baseaddr, 1); | 783 | iocled->mmioaddr = ioremap(baseaddr, 1); |
784 | if (!iocled->mmioaddr) | 784 | if (!iocled->mmioaddr) |
785 | return; | 785 | goto out_free; |
786 | iocled->chip.get = txx9_iocled_get; | 786 | iocled->chip.get = txx9_iocled_get; |
787 | iocled->chip.set = txx9_iocled_set; | 787 | iocled->chip.set = txx9_iocled_set; |
788 | iocled->chip.direction_input = txx9_iocled_dir_in; | 788 | iocled->chip.direction_input = txx9_iocled_dir_in; |
@@ -791,13 +791,13 @@ void __init txx9_iocled_init(unsigned long baseaddr, | |||
791 | iocled->chip.base = basenum; | 791 | iocled->chip.base = basenum; |
792 | iocled->chip.ngpio = num; | 792 | iocled->chip.ngpio = num; |
793 | if (gpiochip_add(&iocled->chip)) | 793 | if (gpiochip_add(&iocled->chip)) |
794 | return; | 794 | goto out_unmap; |
795 | if (basenum < 0) | 795 | if (basenum < 0) |
796 | basenum = iocled->chip.base; | 796 | basenum = iocled->chip.base; |
797 | 797 | ||
798 | pdev = platform_device_alloc("leds-gpio", basenum); | 798 | pdev = platform_device_alloc("leds-gpio", basenum); |
799 | if (!pdev) | 799 | if (!pdev) |
800 | return; | 800 | goto out_gpio; |
801 | iocled->pdata.num_leds = num; | 801 | iocled->pdata.num_leds = num; |
802 | iocled->pdata.leds = iocled->leds; | 802 | iocled->pdata.leds = iocled->leds; |
803 | for (i = 0; i < num; i++) { | 803 | for (i = 0; i < num; i++) { |
@@ -812,7 +812,16 @@ void __init txx9_iocled_init(unsigned long baseaddr, | |||
812 | } | 812 | } |
813 | pdev->dev.platform_data = &iocled->pdata; | 813 | pdev->dev.platform_data = &iocled->pdata; |
814 | if (platform_device_add(pdev)) | 814 | if (platform_device_add(pdev)) |
815 | platform_device_put(pdev); | 815 | goto out_pdev; |
816 | return; | ||
817 | out_pdev: | ||
818 | platform_device_put(pdev); | ||
819 | out_gpio: | ||
820 | gpio_remove(&iocled->chip); | ||
821 | out_unmap: | ||
822 | iounmap(iocled->mmioaddr); | ||
823 | out_free: | ||
824 | kfree(iocled); | ||
816 | } | 825 | } |
817 | #else /* CONFIG_LEDS_GPIO */ | 826 | #else /* CONFIG_LEDS_GPIO */ |
818 | void __init txx9_iocled_init(unsigned long baseaddr, | 827 | void __init txx9_iocled_init(unsigned long baseaddr, |