diff options
author | Julia Lawall <julia@diku.dk> | 2008-02-05 02:34:59 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-02-06 06:06:59 -0500 |
commit | b1725c9319aae42d7bd1159fc99e033d5a3076f8 (patch) | |
tree | 776c5ce1711019a6dac4c43899c1541a2a49fdda /arch/powerpc | |
parent | 842decbd674106d63a67e07a2f8cec5af70fdb40 (diff) |
[POWERPC] arch/powerpc/sysdev: Add missing of_node_put
The functions of_find_compatible_node and of_find_node_by_type both
call of_node_get on their result. So any error handling code
thereafter should call of_node_put(np). This is taken care of in the
case where there is a goto out, but not when there is a direct return.
The function irq_alloc_host puts np into the returned structure, which is
stored in the global variable mpc8xx_pic_host, so the reference count
should be set for the lifetime of that variable. The current solution ups
the reference count again in the argument to irq_alloc_host so that it can
be decremented on the way out. This seems a bit unnecessary, and also
doesn't work in the case where irq_alloc_host fails, because then the
reference count only goes does by one, whereas it should go down by two. A
better solution is to not increment the reference count in the argument to
irq_alloc_host and only decrement it on the way out in an error case.
The problem was found using the following semantic match.
(http://www.emn.fr/x-info/coccinelle/)
// <smpl>
@@
type T,T1,T2;
identifier E;
statement S;
expression x1,x2,x3;
int ret;
@@
T E;
...
* E = \(of_get_parent\|of_find_compatible_node\)(...);
if (E == NULL) S
... when != of_node_put(...,(T1)E,...)
when != if (E != NULL) { ... of_node_put(...,(T1)E,...); ...}
when != x1 = (T1)E
when != E = x3;
when any
if (...) {
... when != of_node_put(...,(T2)E,...)
when != if (E != NULL) { ... of_node_put(...,(T2)E,...); ...}
when != x2 = (T2)E
(
* return;
|
* return ret;
)
}
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Kumar Gala <galak@gate.crashing.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/sysdev/mpc8xx_pic.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/arch/powerpc/sysdev/mpc8xx_pic.c b/arch/powerpc/sysdev/mpc8xx_pic.c index 0e74a4bd9827..5d2d5522ef41 100644 --- a/arch/powerpc/sysdev/mpc8xx_pic.c +++ b/arch/powerpc/sysdev/mpc8xx_pic.c | |||
@@ -174,15 +174,19 @@ int mpc8xx_pic_init(void) | |||
174 | goto out; | 174 | goto out; |
175 | 175 | ||
176 | siu_reg = ioremap(res.start, res.end - res.start + 1); | 176 | siu_reg = ioremap(res.start, res.end - res.start + 1); |
177 | if (siu_reg == NULL) | 177 | if (siu_reg == NULL) { |
178 | return -EINVAL; | 178 | ret = -EINVAL; |
179 | goto out; | ||
180 | } | ||
179 | 181 | ||
180 | mpc8xx_pic_host = irq_alloc_host(of_node_get(np), IRQ_HOST_MAP_LINEAR, | 182 | mpc8xx_pic_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, |
181 | 64, &mpc8xx_pic_host_ops, 64); | 183 | 64, &mpc8xx_pic_host_ops, 64); |
182 | if (mpc8xx_pic_host == NULL) { | 184 | if (mpc8xx_pic_host == NULL) { |
183 | printk(KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n"); | 185 | printk(KERN_ERR "MPC8xx PIC: failed to allocate irq host!\n"); |
184 | ret = -ENOMEM; | 186 | ret = -ENOMEM; |
187 | goto out; | ||
185 | } | 188 | } |
189 | return 0; | ||
186 | 190 | ||
187 | out: | 191 | out: |
188 | of_node_put(np); | 192 | of_node_put(np); |