node: make clear that ->parent is valid until destruction
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Dec 2014 14:57:18 +0000 (15:57 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 22 Dec 2014 16:19:39 +0000 (17:19 +0100)
So far we pretended that ->parent is no longer valid once a node was
deactivated. However, we always pinned the parent until destruction for
several reasons. Update our comments to make this clear.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
node.c
node.h

diff --git a/node.c b/node.c
index 96cd2aa88facf0d8725d6eab1f9e2b5af1c4cb45..cc03ee53c832c655299d150621d8460680c98a15 100644 (file)
--- a/node.c
+++ b/node.c
  *
  *     * node->lock:     lock to protect node->children, node->rb, node->parent
  *     * node->parent: Reference to parent node. This is set during LINK time
- *                     and is dropped during deactivation. You must not access
- *                     it unless you hold an active reference to the node.
+ *                     and is dropped during destruction. You must not access
+ *                     it unless you hold an active reference to the node or if
+ *                     you know the node is dead.
  *     * node->children: rb-tree of all linked children of this node. You must
  *                       not access this directly, but use one of the iterator
  *                       or lookup helpers.
@@ -450,6 +451,12 @@ struct kdbus_node *kdbus_node_unref(struct kdbus_node *node)
                up_write(&kdbus_node_idr_lock);
 
                kfree(safe.name);
+
+               /*
+                * kdbusfs relies on the parent to be available even after the
+                * node was deactivated and unlinked. Therefore, we pin it
+                * until a node is destroyed.
+                */
                kdbus_node_unref(safe.parent);
        }
 
diff --git a/node.h b/node.h
index d907dcc9a36c3b3e54828d6951f1c42b7c22f6d5..31f2a84a152c42706758105d52b9d77f8ab85d8b 100644 (file)
--- a/node.h
+++ b/node.h
@@ -51,12 +51,12 @@ struct kdbus_node {
        char *name;
        unsigned int hash;
        unsigned int id;
+       struct kdbus_node *parent; /* may be NULL */
 
        /* valid iff active */
        struct mutex lock;
        struct rb_node rb;
        struct rb_root children;
-       struct kdbus_node *parent;
 };
 
 #define kdbus_node_from_rb(_node) rb_entry((_node), struct kdbus_node, rb)