aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-01-28 15:52:53 -0500
committerGrant Likely <grant.likely@secretlab.ca>2010-01-28 15:52:53 -0500
commit923f7e30b480438f1e86e01e5cde814248b59a39 (patch)
treead9cb0e701b0a8ef2ac5113fbd4a42118039edd6 /drivers/of
parent1f43cfb9474d1c4f22598b6e3213ec035be6dd56 (diff)
of: Merge of_node_get() and of_node_put()
Merge common code between PowerPC and MicroBlaze Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Tested-by: Wolfram Sang <w.sang@pengutronix.de> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index dba995b70b8..cf89ee6253f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -60,6 +60,81 @@ int of_n_size_cells(struct device_node *np)
60} 60}
61EXPORT_SYMBOL(of_n_size_cells); 61EXPORT_SYMBOL(of_n_size_cells);
62 62
63#if !defined(CONFIG_SPARC) /* SPARC doesn't do ref counting (yet) */
64/**
65 * of_node_get - Increment refcount of a node
66 * @node: Node to inc refcount, NULL is supported to
67 * simplify writing of callers
68 *
69 * Returns node.
70 */
71struct device_node *of_node_get(struct device_node *node)
72{
73 if (node)
74 kref_get(&node->kref);
75 return node;
76}
77EXPORT_SYMBOL(of_node_get);
78
79static inline struct device_node *kref_to_device_node(struct kref *kref)
80{
81 return container_of(kref, struct device_node, kref);
82}
83
84/**
85 * of_node_release - release a dynamically allocated node
86 * @kref: kref element of the node to be released
87 *
88 * In of_node_put() this function is passed to kref_put()
89 * as the destructor.
90 */
91static void of_node_release(struct kref *kref)
92{
93 struct device_node *node = kref_to_device_node(kref);
94 struct property *prop = node->properties;
95
96 /* We should never be releasing nodes that haven't been detached. */
97 if (!of_node_check_flag(node, OF_DETACHED)) {
98 pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name);
99 dump_stack();
100 kref_init(&node->kref);
101 return;
102 }
103
104 if (!of_node_check_flag(node, OF_DYNAMIC))
105 return;
106
107 while (prop) {
108 struct property *next = prop->next;
109 kfree(prop->name);
110 kfree(prop->value);
111 kfree(prop);
112 prop = next;
113
114 if (!prop) {
115 prop = node->deadprops;
116 node->deadprops = NULL;
117 }
118 }
119 kfree(node->full_name);
120 kfree(node->data);
121 kfree(node);
122}
123
124/**
125 * of_node_put - Decrement refcount of a node
126 * @node: Node to dec refcount, NULL is supported to
127 * simplify writing of callers
128 *
129 */
130void of_node_put(struct device_node *node)
131{
132 if (node)
133 kref_put(&node->kref, of_node_release);
134}
135EXPORT_SYMBOL(of_node_put);
136#endif /* !CONFIG_SPARC */
137
63struct property *of_find_property(const struct device_node *np, 138struct property *of_find_property(const struct device_node *np,
64 const char *name, 139 const char *name,
65 int *lenp) 140 int *lenp)