diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-04-24 02:46:53 -0400 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-07-19 23:32:24 -0400 |
commit | 581b605a83ec241a2aff8ef780e08b9414c8dfd8 (patch) | |
tree | 809640a0dc3a1bd0b5afba795cf9f6357f6e3a81 | |
parent | 0081cbc3731de8ad4744ba433af51f17bf27eb9c (diff) |
Consolidate of_find_property
The only change here is that a readlock is taken while the property list
is being traversed on Sparc where it was not taken previously.
Also, Sparc uses strcasecmp to compare property names while PowerPC
uses strcmp.
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Paul Mackerras <paulus@samba.org>
Acked-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | arch/powerpc/kernel/prom.c | 24 | ||||
-rw-r--r-- | arch/sparc/kernel/prom.c | 22 | ||||
-rw-r--r-- | arch/sparc64/kernel/prom.c | 22 | ||||
-rw-r--r-- | drivers/of/base.c | 26 | ||||
-rw-r--r-- | include/asm-powerpc/prom.h | 1 | ||||
-rw-r--r-- | include/asm-sparc/prom.h | 1 | ||||
-rw-r--r-- | include/asm-sparc64/prom.h | 1 |
7 files changed, 32 insertions, 65 deletions
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index c009d2155f9c..3f6238d96a5d 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c | |||
@@ -80,10 +80,7 @@ struct boot_param_header *initial_boot_params; | |||
80 | 80 | ||
81 | static struct device_node *allnodes = NULL; | 81 | static struct device_node *allnodes = NULL; |
82 | 82 | ||
83 | /* use when traversing tree through the allnext, child, sibling, | 83 | extern rwlock_t devtree_lock; /* temporary while merging */ |
84 | * or parent members of struct device_node. | ||
85 | */ | ||
86 | static DEFINE_RWLOCK(devtree_lock); | ||
87 | 84 | ||
88 | /* export that to outside world */ | 85 | /* export that to outside world */ |
89 | struct device_node *of_chosen; | 86 | struct device_node *of_chosen; |
@@ -1489,25 +1486,6 @@ static int __init prom_reconfig_setup(void) | |||
1489 | __initcall(prom_reconfig_setup); | 1486 | __initcall(prom_reconfig_setup); |
1490 | #endif | 1487 | #endif |
1491 | 1488 | ||
1492 | struct property *of_find_property(const struct device_node *np, | ||
1493 | const char *name, | ||
1494 | int *lenp) | ||
1495 | { | ||
1496 | struct property *pp; | ||
1497 | |||
1498 | read_lock(&devtree_lock); | ||
1499 | for (pp = np->properties; pp != 0; pp = pp->next) | ||
1500 | if (strcmp(pp->name, name) == 0) { | ||
1501 | if (lenp != 0) | ||
1502 | *lenp = pp->length; | ||
1503 | break; | ||
1504 | } | ||
1505 | read_unlock(&devtree_lock); | ||
1506 | |||
1507 | return pp; | ||
1508 | } | ||
1509 | EXPORT_SYMBOL(of_find_property); | ||
1510 | |||
1511 | /* | 1489 | /* |
1512 | * Add a property to a node | 1490 | * Add a property to a node |
1513 | */ | 1491 | */ |
diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index f2ce0d48e102..0f5aab4326b3 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c | |||
@@ -27,10 +27,7 @@ | |||
27 | 27 | ||
28 | static struct device_node *allnodes; | 28 | static struct device_node *allnodes; |
29 | 29 | ||
30 | /* use when traversing tree through the allnext, child, sibling, | 30 | extern rwlock_t devtree_lock; /* temporary while merging */ |
31 | * or parent members of struct device_node. | ||
32 | */ | ||
33 | static DEFINE_RWLOCK(devtree_lock); | ||
34 | 31 | ||
35 | struct device_node *of_get_parent(const struct device_node *node) | 32 | struct device_node *of_get_parent(const struct device_node *node) |
36 | { | 33 | { |
@@ -130,23 +127,6 @@ struct device_node *of_find_compatible_node(struct device_node *from, | |||
130 | } | 127 | } |
131 | EXPORT_SYMBOL(of_find_compatible_node); | 128 | EXPORT_SYMBOL(of_find_compatible_node); |
132 | 129 | ||
133 | struct property *of_find_property(const struct device_node *np, | ||
134 | const char *name, | ||
135 | int *lenp) | ||
136 | { | ||
137 | struct property *pp; | ||
138 | |||
139 | for (pp = np->properties; pp != 0; pp = pp->next) { | ||
140 | if (strcasecmp(pp->name, name) == 0) { | ||
141 | if (lenp != 0) | ||
142 | *lenp = pp->length; | ||
143 | break; | ||
144 | } | ||
145 | } | ||
146 | return pp; | ||
147 | } | ||
148 | EXPORT_SYMBOL(of_find_property); | ||
149 | |||
150 | int of_getintprop_default(struct device_node *np, const char *name, int def) | 130 | int of_getintprop_default(struct device_node *np, const char *name, int def) |
151 | { | 131 | { |
152 | struct property *prop; | 132 | struct property *prop; |
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index 4d6fb07f047f..a1ccc00c7958 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c | |||
@@ -32,10 +32,7 @@ | |||
32 | 32 | ||
33 | static struct device_node *allnodes; | 33 | static struct device_node *allnodes; |
34 | 34 | ||
35 | /* use when traversing tree through the allnext, child, sibling, | 35 | extern rwlock_t devtree_lock; /* temporary while merging */ |
36 | * or parent members of struct device_node. | ||
37 | */ | ||
38 | static DEFINE_RWLOCK(devtree_lock); | ||
39 | 36 | ||
40 | struct device_node *of_get_parent(const struct device_node *node) | 37 | struct device_node *of_get_parent(const struct device_node *node) |
41 | { | 38 | { |
@@ -135,23 +132,6 @@ struct device_node *of_find_compatible_node(struct device_node *from, | |||
135 | } | 132 | } |
136 | EXPORT_SYMBOL(of_find_compatible_node); | 133 | EXPORT_SYMBOL(of_find_compatible_node); |
137 | 134 | ||
138 | struct property *of_find_property(const struct device_node *np, | ||
139 | const char *name, | ||
140 | int *lenp) | ||
141 | { | ||
142 | struct property *pp; | ||
143 | |||
144 | for (pp = np->properties; pp != 0; pp = pp->next) { | ||
145 | if (strcasecmp(pp->name, name) == 0) { | ||
146 | if (lenp != 0) | ||
147 | *lenp = pp->length; | ||
148 | break; | ||
149 | } | ||
150 | } | ||
151 | return pp; | ||
152 | } | ||
153 | EXPORT_SYMBOL(of_find_property); | ||
154 | |||
155 | int of_getintprop_default(struct device_node *np, const char *name, int def) | 135 | int of_getintprop_default(struct device_node *np, const char *name, int def) |
156 | { | 136 | { |
157 | struct property *prop; | 137 | struct property *prop; |
diff --git a/drivers/of/base.c b/drivers/of/base.c index d6dc5e74c27c..70b60845140e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -18,6 +18,12 @@ | |||
18 | */ | 18 | */ |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/of.h> | 20 | #include <linux/of.h> |
21 | #include <linux/spinlock.h> | ||
22 | |||
23 | /* use when traversing tree through the allnext, child, sibling, | ||
24 | * or parent members of struct device_node. | ||
25 | */ | ||
26 | DEFINE_RWLOCK(devtree_lock); | ||
21 | 27 | ||
22 | int of_n_addr_cells(struct device_node *np) | 28 | int of_n_addr_cells(struct device_node *np) |
23 | { | 29 | { |
@@ -51,6 +57,26 @@ int of_n_size_cells(struct device_node *np) | |||
51 | } | 57 | } |
52 | EXPORT_SYMBOL(of_n_size_cells); | 58 | EXPORT_SYMBOL(of_n_size_cells); |
53 | 59 | ||
60 | struct property *of_find_property(const struct device_node *np, | ||
61 | const char *name, | ||
62 | int *lenp) | ||
63 | { | ||
64 | struct property *pp; | ||
65 | |||
66 | read_lock(&devtree_lock); | ||
67 | for (pp = np->properties; pp != 0; pp = pp->next) { | ||
68 | if (of_prop_cmp(pp->name, name) == 0) { | ||
69 | if (lenp != 0) | ||
70 | *lenp = pp->length; | ||
71 | break; | ||
72 | } | ||
73 | } | ||
74 | read_unlock(&devtree_lock); | ||
75 | |||
76 | return pp; | ||
77 | } | ||
78 | EXPORT_SYMBOL(of_find_property); | ||
79 | |||
54 | /* | 80 | /* |
55 | * Find a property with a given name for a given node | 81 | * Find a property with a given name for a given node |
56 | * and return the value. | 82 | * and return the value. |
diff --git a/include/asm-powerpc/prom.h b/include/asm-powerpc/prom.h index b05f8f26940a..75b1144ca580 100644 --- a/include/asm-powerpc/prom.h +++ b/include/asm-powerpc/prom.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | 25 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 |
26 | 26 | ||
27 | #define of_compat_cmp(s1, s2, l) strncasecmp((s1), (s2), (l)) | 27 | #define of_compat_cmp(s1, s2, l) strncasecmp((s1), (s2), (l)) |
28 | #define of_prop_cmp(s1, s2) strcmp((s1), (s2)) | ||
28 | 29 | ||
29 | /* Definitions used by the flattened device tree */ | 30 | /* Definitions used by the flattened device tree */ |
30 | #define OF_DT_HEADER 0xd00dfeed /* marker */ | 31 | #define OF_DT_HEADER 0xd00dfeed /* marker */ |
diff --git a/include/asm-sparc/prom.h b/include/asm-sparc/prom.h index c755c69404f7..57f86c84293b 100644 --- a/include/asm-sparc/prom.h +++ b/include/asm-sparc/prom.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | 24 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 |
25 | 25 | ||
26 | #define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l)) | 26 | #define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l)) |
27 | #define of_prop_cmp(s1, s2) strcasecmp((s1), (s2)) | ||
27 | 28 | ||
28 | typedef u32 phandle; | 29 | typedef u32 phandle; |
29 | typedef u32 ihandle; | 30 | typedef u32 ihandle; |
diff --git a/include/asm-sparc64/prom.h b/include/asm-sparc64/prom.h index 040d198ee842..6a5e2405cbf4 100644 --- a/include/asm-sparc64/prom.h +++ b/include/asm-sparc64/prom.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 | 24 | #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1 |
25 | 25 | ||
26 | #define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l)) | 26 | #define of_compat_cmp(s1, s2, l) strncmp((s1), (s2), (l)) |
27 | #define of_prop_cmp(s1, s2) strcasecmp((s1), (s2)) | ||
27 | 28 | ||
28 | typedef u32 phandle; | 29 | typedef u32 phandle; |
29 | typedef u32 ihandle; | 30 | typedef u32 ihandle; |