]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[POWERPC] Add a warning to help trackdown device_node refcounting bugs
authorMichael Ellerman <michael@ellerman.id.au>
Tue, 19 Jun 2007 06:08:00 +0000 (16:08 +1000)
committerPaul Mackerras <paulus@samba.org>
Tue, 10 Jul 2007 11:53:47 +0000 (21:53 +1000)
When the refcount for a device node goes to 0, we call the
destructor - of_node_release(). This should only happen if we've
already detached the node from the device tree.

So add a flag OF_DETACHED which tracks detached-ness, and if we
find ourselves in of_node_release() without it set, issue a
warning and don't free the device_node. To avoid warning
continuously reinitialise the kref to a sane value.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/kernel/prom.c
include/asm-powerpc/prom.h

index bcd1c5ed44a35066be85372366f9d6240c409e88..6d5e601097a0df33f65e4fca29144719915e6541 100644 (file)
@@ -1375,8 +1375,17 @@ static void of_node_release(struct kref *kref)
        struct device_node *node = kref_to_device_node(kref);
        struct property *prop = node->properties;
 
+       /* We should never be releasing nodes that haven't been detached. */
+       if (!of_node_check_flag(node, OF_DETACHED)) {
+               printk("WARNING: Bad of_node_put() on %s\n", node->full_name);
+               dump_stack();
+               kref_init(&node->kref);
+               return;
+       }
+
        if (!of_node_check_flag(node, OF_DYNAMIC))
                return;
+
        while (prop) {
                struct property *next = prop->next;
                kfree(prop->name);
@@ -1457,6 +1466,8 @@ void of_detach_node(const struct device_node *np)
                prevsib->sibling = np->sibling;
        }
 
+       of_node_set_flag(np, OF_DETACHED);
+
 out_unlock:
        write_unlock(&devtree_lock);
 }
index f1006b91bd1a40649f79a130ff728cabc9b389ef..1632baa17dc6964f0ae9bd7234b3bb350726bcec 100644 (file)
@@ -99,6 +99,7 @@ extern struct device_node *of_chosen;
 
 /* flag descriptions */
 #define OF_DYNAMIC     1 /* node and properties were allocated via kmalloc */
+#define OF_DETACHED    2 /* node has been detached from the device tree */
 
 static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
 {