aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--arch/microblaze/kernel/prom.c74
-rw-r--r--arch/powerpc/kernel/prom.c73
-rw-r--r--drivers/of/base.c75
3 files changed, 75 insertions, 147 deletions
diff --git a/arch/microblaze/kernel/prom.c b/arch/microblaze/kernel/prom.c
index 16a001c71e2e..46407e643926 100644
--- a/arch/microblaze/kernel/prom.c
+++ b/arch/microblaze/kernel/prom.c
@@ -350,80 +350,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
350} 350}
351EXPORT_SYMBOL(of_find_node_by_phandle); 351EXPORT_SYMBOL(of_find_node_by_phandle);
352 352
353/**
354 * of_node_get - Increment refcount of a node
355 * @node: Node to inc refcount, NULL is supported to
356 * simplify writing of callers
357 *
358 * Returns node.
359 */
360struct device_node *of_node_get(struct device_node *node)
361{
362 if (node)
363 kref_get(&node->kref);
364 return node;
365}
366EXPORT_SYMBOL(of_node_get);
367
368static inline struct device_node *kref_to_device_node(struct kref *kref)
369{
370 return container_of(kref, struct device_node, kref);
371}
372
373/**
374 * of_node_release - release a dynamically allocated node
375 * @kref: kref element of the node to be released
376 *
377 * In of_node_put() this function is passed to kref_put()
378 * as the destructor.
379 */
380static void of_node_release(struct kref *kref)
381{
382 struct device_node *node = kref_to_device_node(kref);
383 struct property *prop = node->properties;
384
385 /* We should never be releasing nodes that haven't been detached. */
386 if (!of_node_check_flag(node, OF_DETACHED)) {
387 printk(KERN_INFO "WARNING: Bad of_node_put() on %s\n",
388 node->full_name);
389 dump_stack();
390 kref_init(&node->kref);
391 return;
392 }
393
394 if (!of_node_check_flag(node, OF_DYNAMIC))
395 return;
396
397 while (prop) {
398 struct property *next = prop->next;
399 kfree(prop->name);
400 kfree(prop->value);
401 kfree(prop);
402 prop = next;
403
404 if (!prop) {
405 prop = node->deadprops;
406 node->deadprops = NULL;
407 }
408 }
409 kfree(node->full_name);
410 kfree(node->data);
411 kfree(node);
412}
413
414/**
415 * of_node_put - Decrement refcount of a node
416 * @node: Node to dec refcount, NULL is supported to
417 * simplify writing of callers
418 *
419 */
420void of_node_put(struct device_node *node)
421{
422 if (node)
423 kref_put(&node->kref, of_node_release);
424}
425EXPORT_SYMBOL(of_node_put);
426
427/* 353/*
428 * Plug a device node into the tree and global list. 354 * Plug a device node into the tree and global list.
429 */ 355 */
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index caeea9a5fcc2..deccd91d7e81 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -817,79 +817,6 @@ struct device_node *of_find_next_cache_node(struct device_node *np)
817 return NULL; 817 return NULL;
818} 818}
819 819
820/**
821 * of_node_get - Increment refcount of a node
822 * @node: Node to inc refcount, NULL is supported to
823 * simplify writing of callers
824 *
825 * Returns node.
826 */
827struct device_node *of_node_get(struct device_node *node)
828{
829 if (node)
830 kref_get(&node->kref);
831 return node;
832}
833EXPORT_SYMBOL(of_node_get);
834
835static inline struct device_node * kref_to_device_node(struct kref *kref)
836{
837 return container_of(kref, struct device_node, kref);
838}
839
840/**
841 * of_node_release - release a dynamically allocated node
842 * @kref: kref element of the node to be released
843 *
844 * In of_node_put() this function is passed to kref_put()
845 * as the destructor.
846 */
847static void of_node_release(struct kref *kref)
848{
849 struct device_node *node = kref_to_device_node(kref);
850 struct property *prop = node->properties;
851
852 /* We should never be releasing nodes that haven't been detached. */
853 if (!of_node_check_flag(node, OF_DETACHED)) {
854 printk("WARNING: Bad of_node_put() on %s\n", node->full_name);
855 dump_stack();
856 kref_init(&node->kref);
857 return;
858 }
859
860 if (!of_node_check_flag(node, OF_DYNAMIC))
861 return;
862
863 while (prop) {
864 struct property *next = prop->next;
865 kfree(prop->name);
866 kfree(prop->value);
867 kfree(prop);
868 prop = next;
869
870 if (!prop) {
871 prop = node->deadprops;
872 node->deadprops = NULL;
873 }
874 }
875 kfree(node->full_name);
876 kfree(node->data);
877 kfree(node);
878}
879
880/**
881 * of_node_put - Decrement refcount of a node
882 * @node: Node to dec refcount, NULL is supported to
883 * simplify writing of callers
884 *
885 */
886void of_node_put(struct device_node *node)
887{
888 if (node)
889 kref_put(&node->kref, of_node_release);
890}
891EXPORT_SYMBOL(of_node_put);
892
893/* 820/*
894 * Plug a device node into the tree and global list. 821 * Plug a device node into the tree and global list.
895 */ 822 */
diff --git a/drivers/of/base.c b/drivers/of/base.c
index dba995b70b84..cf89ee6253f3 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)