powerpc/irq.c: Add of_node_put to avoid memory leak
authorJulia Lawall <julia@diku.dk>
Sat, 4 Sep 2010 00:12:44 +0000 (00:12 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 13 Oct 2010 05:19:04 +0000 (16:19 +1100)
commita655237fa2f9e4afe9949abe2c511432ab9537dd
treeae4ecac9434e48d4da63aa8d96fcaa7e3296e6f7
parent689fd14ae9b2af5c6862ddc11d4791ec9a938cb3
powerpc/irq.c: Add of_node_put to avoid memory leak

In this case, a device_node structure is stored in another structure that
is then freed without first decrementing the reference count of the
device_node structure.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
expression x;
identifier f;
position p1,p2;
@@

x@p1->f = \(of_find_node_by_path\|of_find_node_by_name\|of_find_node_by_phandle\|of_get_parent\|of_get_next_parent\|of_get_next_child\|of_find_compatible_node\|of_match_node\|of_find_node_by_type\|of_find_node_with_property\|of_find_matching_node\|of_parse_phandle\|of_node_get\)(...);
... when != of_node_put(x)
kfree@p2(x)

@script:python@
p1 << r.p1;
p2 << r.p2;
@@
cocci.print_main("call",p1)
cocci.print_secs("free",p2)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/kernel/irq.c