|
@@ -60,6 +60,81 @@ int of_n_size_cells(struct device_node *np)
|
|
|
}
|
|
|
EXPORT_SYMBOL(of_n_size_cells);
|
|
|
|
|
|
+#if !defined(CONFIG_SPARC) /* SPARC doesn't do ref counting (yet) */
|
|
|
+/**
|
|
|
+ * of_node_get - Increment refcount of a node
|
|
|
+ * @node: Node to inc refcount, NULL is supported to
|
|
|
+ * simplify writing of callers
|
|
|
+ *
|
|
|
+ * Returns node.
|
|
|
+ */
|
|
|
+struct device_node *of_node_get(struct device_node *node)
|
|
|
+{
|
|
|
+ if (node)
|
|
|
+ kref_get(&node->kref);
|
|
|
+ return node;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(of_node_get);
|
|
|
+
|
|
|
+static inline struct device_node *kref_to_device_node(struct kref *kref)
|
|
|
+{
|
|
|
+ return container_of(kref, struct device_node, kref);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * of_node_release - release a dynamically allocated node
|
|
|
+ * @kref: kref element of the node to be released
|
|
|
+ *
|
|
|
+ * In of_node_put() this function is passed to kref_put()
|
|
|
+ * as the destructor.
|
|
|
+ */
|
|
|
+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)) {
|
|
|
+ pr_err("ERROR: 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);
|
|
|
+ kfree(prop->value);
|
|
|
+ kfree(prop);
|
|
|
+ prop = next;
|
|
|
+
|
|
|
+ if (!prop) {
|
|
|
+ prop = node->deadprops;
|
|
|
+ node->deadprops = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kfree(node->full_name);
|
|
|
+ kfree(node->data);
|
|
|
+ kfree(node);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * of_node_put - Decrement refcount of a node
|
|
|
+ * @node: Node to dec refcount, NULL is supported to
|
|
|
+ * simplify writing of callers
|
|
|
+ *
|
|
|
+ */
|
|
|
+void of_node_put(struct device_node *node)
|
|
|
+{
|
|
|
+ if (node)
|
|
|
+ kref_put(&node->kref, of_node_release);
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(of_node_put);
|
|
|
+#endif /* !CONFIG_SPARC */
|
|
|
+
|
|
|
struct property *of_find_property(const struct device_node *np,
|
|
|
const char *name,
|
|
|
int *lenp)
|