diff options
author | Frank Rowand <frank.rowand@am.sony.com> | 2016-10-29 02:26:26 -0400 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2016-11-15 10:17:15 -0500 |
commit | 25e1687767612e593c054d5855f6717cf8104c1f (patch) | |
tree | 6ce0aa53a4e7cba8383c069fe2690a8da7ec1bea /drivers/of/resolver.c | |
parent | fad556bf3f5a9182aa8ec9d1a988735dabfd6631 (diff) |
of: Rename variables to better reflect purpose or follow convention
Rename variables to better reflect what their purpose is. As a side
effect, this reduces the need for some of the comments previously
removed in this series.
Signed-off-by: Frank Rowand <frank.rowand@am.sony.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of/resolver.c')
-rw-r--r-- | drivers/of/resolver.c | 172 |
1 files changed, 85 insertions, 87 deletions
diff --git a/drivers/of/resolver.c b/drivers/of/resolver.c index 0ce38aa0ed3c..0778747cdd58 100644 --- a/drivers/of/resolver.c +++ b/drivers/of/resolver.c | |||
@@ -74,17 +74,17 @@ static phandle live_tree_max_phandle(void) | |||
74 | /* | 74 | /* |
75 | * Adjust a subtree's phandle values by a given delta. | 75 | * Adjust a subtree's phandle values by a given delta. |
76 | */ | 76 | */ |
77 | static void adjust_overlay_phandles(struct device_node *node, | 77 | static void adjust_overlay_phandles(struct device_node *overlay, |
78 | int phandle_delta) | 78 | int phandle_delta) |
79 | { | 79 | { |
80 | struct device_node *child; | 80 | struct device_node *child; |
81 | struct property *prop; | 81 | struct property *prop; |
82 | phandle phandle; | 82 | phandle phandle; |
83 | 83 | ||
84 | if (node->phandle != 0 && node->phandle != OF_PHANDLE_ILLEGAL) | 84 | if (overlay->phandle != 0 && overlay->phandle != OF_PHANDLE_ILLEGAL) |
85 | node->phandle += phandle_delta; | 85 | overlay->phandle += phandle_delta; |
86 | 86 | ||
87 | for_each_property_of_node(node, prop) { | 87 | for_each_property_of_node(overlay, prop) { |
88 | 88 | ||
89 | if (of_prop_cmp(prop->name, "phandle") && | 89 | if (of_prop_cmp(prop->name, "phandle") && |
90 | of_prop_cmp(prop->name, "linux,phandle")) | 90 | of_prop_cmp(prop->name, "linux,phandle")) |
@@ -97,41 +97,40 @@ static void adjust_overlay_phandles(struct device_node *node, | |||
97 | if (phandle == OF_PHANDLE_ILLEGAL) | 97 | if (phandle == OF_PHANDLE_ILLEGAL) |
98 | continue; | 98 | continue; |
99 | 99 | ||
100 | *(uint32_t *)prop->value = cpu_to_be32(node->phandle); | 100 | *(uint32_t *)prop->value = cpu_to_be32(overlay->phandle); |
101 | } | 101 | } |
102 | 102 | ||
103 | for_each_child_of_node(node, child) | 103 | for_each_child_of_node(overlay, child) |
104 | adjust_overlay_phandles(child, phandle_delta); | 104 | adjust_overlay_phandles(child, phandle_delta); |
105 | } | 105 | } |
106 | 106 | ||
107 | static int update_usages_of_a_phandle_reference(struct device_node *node, | 107 | static int update_usages_of_a_phandle_reference(struct device_node *overlay, |
108 | struct property *rprop, int value) | 108 | struct property *prop_fixup, phandle phandle) |
109 | { | 109 | { |
110 | phandle phandle; | ||
111 | struct device_node *refnode; | 110 | struct device_node *refnode; |
112 | struct property *sprop; | 111 | struct property *prop; |
113 | char *propval, *propcur, *propend, *nodestr, *propstr, *s; | 112 | char *value, *cur, *end, *node_path, *prop_name, *s; |
114 | int offset, propcurlen; | 113 | int offset, len; |
115 | int err = 0; | 114 | int err = 0; |
116 | 115 | ||
117 | propval = kmalloc(rprop->length, GFP_KERNEL); | 116 | value = kmalloc(prop_fixup->length, GFP_KERNEL); |
118 | if (!propval) | 117 | if (!value) |
119 | return -ENOMEM; | 118 | return -ENOMEM; |
120 | memcpy(propval, rprop->value, rprop->length); | 119 | memcpy(value, prop_fixup->value, prop_fixup->length); |
121 | 120 | ||
122 | propend = propval + rprop->length; | 121 | end = value + prop_fixup->length; |
123 | for (propcur = propval; propcur < propend; propcur += propcurlen + 1) { | 122 | for (cur = value; cur < end; cur += len + 1) { |
124 | propcurlen = strlen(propcur); | 123 | len = strlen(cur); |
125 | 124 | ||
126 | nodestr = propcur; | 125 | node_path = cur; |
127 | s = strchr(propcur, ':'); | 126 | s = strchr(cur, ':'); |
128 | if (!s) { | 127 | if (!s) { |
129 | err = -EINVAL; | 128 | err = -EINVAL; |
130 | goto err_fail; | 129 | goto err_fail; |
131 | } | 130 | } |
132 | *s++ = '\0'; | 131 | *s++ = '\0'; |
133 | 132 | ||
134 | propstr = s; | 133 | prop_name = s; |
135 | s = strchr(s, ':'); | 134 | s = strchr(s, ':'); |
136 | if (!s) { | 135 | if (!s) { |
137 | err = -EINVAL; | 136 | err = -EINVAL; |
@@ -143,27 +142,26 @@ static int update_usages_of_a_phandle_reference(struct device_node *node, | |||
143 | if (err) | 142 | if (err) |
144 | goto err_fail; | 143 | goto err_fail; |
145 | 144 | ||
146 | refnode = find_node_by_full_name(node, nodestr); | 145 | refnode = find_node_by_full_name(overlay, node_path); |
147 | if (!refnode) | 146 | if (!refnode) |
148 | continue; | 147 | continue; |
149 | 148 | ||
150 | for_each_property_of_node(refnode, sprop) { | 149 | for_each_property_of_node(refnode, prop) { |
151 | if (!of_prop_cmp(sprop->name, propstr)) | 150 | if (!of_prop_cmp(prop->name, prop_name)) |
152 | break; | 151 | break; |
153 | } | 152 | } |
154 | of_node_put(refnode); | 153 | of_node_put(refnode); |
155 | 154 | ||
156 | if (!sprop) { | 155 | if (!prop) { |
157 | err = -ENOENT; | 156 | err = -ENOENT; |
158 | goto err_fail; | 157 | goto err_fail; |
159 | } | 158 | } |
160 | 159 | ||
161 | phandle = value; | 160 | *(__be32 *)(prop->value + offset) = cpu_to_be32(phandle); |
162 | *(__be32 *)(sprop->value + offset) = cpu_to_be32(phandle); | ||
163 | } | 161 | } |
164 | 162 | ||
165 | err_fail: | 163 | err_fail: |
166 | kfree(propval); | 164 | kfree(value); |
167 | return err; | 165 | return err; |
168 | } | 166 | } |
169 | 167 | ||
@@ -184,61 +182,61 @@ static int node_name_cmp(const struct device_node *dn1, | |||
184 | * Does not take any devtree locks so make sure you call this on a tree | 182 | * Does not take any devtree locks so make sure you call this on a tree |
185 | * which is at the detached state. | 183 | * which is at the detached state. |
186 | */ | 184 | */ |
187 | static int adjust_local_phandle_references(struct device_node *node, | 185 | static int adjust_local_phandle_references(struct device_node *local_fixups, |
188 | struct device_node *target, int phandle_delta) | 186 | struct device_node *overlay, int phandle_delta) |
189 | { | 187 | { |
190 | struct device_node *child, *childtarget; | 188 | struct device_node *child, *overlay_child; |
191 | struct property *rprop, *sprop; | 189 | struct property *prop_fix, *prop; |
192 | int err, i, count; | 190 | int err, i, count; |
193 | unsigned int off; | 191 | unsigned int off; |
194 | phandle phandle; | 192 | phandle phandle; |
195 | 193 | ||
196 | if (!node) | 194 | if (!local_fixups) |
197 | return 0; | 195 | return 0; |
198 | 196 | ||
199 | for_each_property_of_node(node, rprop) { | 197 | for_each_property_of_node(local_fixups, prop_fix) { |
200 | 198 | ||
201 | /* skip properties added automatically */ | 199 | /* skip properties added automatically */ |
202 | if (!of_prop_cmp(rprop->name, "name") || | 200 | if (!of_prop_cmp(prop_fix->name, "name") || |
203 | !of_prop_cmp(rprop->name, "phandle") || | 201 | !of_prop_cmp(prop_fix->name, "phandle") || |
204 | !of_prop_cmp(rprop->name, "linux,phandle")) | 202 | !of_prop_cmp(prop_fix->name, "linux,phandle")) |
205 | continue; | 203 | continue; |
206 | 204 | ||
207 | if ((rprop->length % 4) != 0 || rprop->length == 0) | 205 | if ((prop_fix->length % 4) != 0 || prop_fix->length == 0) |
208 | return -EINVAL; | 206 | return -EINVAL; |
209 | count = rprop->length / sizeof(__be32); | 207 | count = prop_fix->length / sizeof(__be32); |
210 | 208 | ||
211 | for_each_property_of_node(target, sprop) { | 209 | for_each_property_of_node(overlay, prop) { |
212 | if (!of_prop_cmp(sprop->name, rprop->name)) | 210 | if (!of_prop_cmp(prop->name, prop_fix->name)) |
213 | break; | 211 | break; |
214 | } | 212 | } |
215 | 213 | ||
216 | if (!sprop) | 214 | if (!prop) |
217 | return -EINVAL; | 215 | return -EINVAL; |
218 | 216 | ||
219 | for (i = 0; i < count; i++) { | 217 | for (i = 0; i < count; i++) { |
220 | off = be32_to_cpu(((__be32 *)rprop->value)[i]); | 218 | off = be32_to_cpu(((__be32 *)prop_fix->value)[i]); |
221 | if (off >= sprop->length || (off + 4) > sprop->length) | 219 | if (off >= prop->length || (off + 4) > prop->length) |
222 | return -EINVAL; | 220 | return -EINVAL; |
223 | 221 | ||
224 | if (phandle_delta) { | 222 | if (phandle_delta) { |
225 | phandle = be32_to_cpu(*(__be32 *)(sprop->value + off)); | 223 | phandle = be32_to_cpu(*(__be32 *)(prop->value + off)); |
226 | phandle += phandle_delta; | 224 | phandle += phandle_delta; |
227 | *(__be32 *)(sprop->value + off) = cpu_to_be32(phandle); | 225 | *(__be32 *)(prop->value + off) = cpu_to_be32(phandle); |
228 | } | 226 | } |
229 | } | 227 | } |
230 | } | 228 | } |
231 | 229 | ||
232 | for_each_child_of_node(node, child) { | 230 | for_each_child_of_node(local_fixups, child) { |
233 | 231 | ||
234 | for_each_child_of_node(target, childtarget) | 232 | for_each_child_of_node(overlay, overlay_child) |
235 | if (!node_name_cmp(child, childtarget)) | 233 | if (!node_name_cmp(child, overlay_child)) |
236 | break; | 234 | break; |
237 | 235 | ||
238 | if (!childtarget) | 236 | if (!overlay_child) |
239 | return -EINVAL; | 237 | return -EINVAL; |
240 | 238 | ||
241 | err = adjust_local_phandle_references(child, childtarget, | 239 | err = adjust_local_phandle_references(child, overlay_child, |
242 | phandle_delta); | 240 | phandle_delta); |
243 | if (err) | 241 | if (err) |
244 | return err; | 242 | return err; |
@@ -260,78 +258,78 @@ static int adjust_local_phandle_references(struct device_node *node, | |||
260 | * are fit to be inserted or operate upon the live tree. | 258 | * are fit to be inserted or operate upon the live tree. |
261 | * Returns 0 on success or a negative error value on error. | 259 | * Returns 0 on success or a negative error value on error. |
262 | */ | 260 | */ |
263 | int of_resolve_phandles(struct device_node *resolve) | 261 | int of_resolve_phandles(struct device_node *overlay) |
264 | { | 262 | { |
265 | struct device_node *child, *childroot, *refnode; | 263 | struct device_node *child, *local_fixups, *refnode; |
266 | struct device_node *root_sym, *resolve_sym, *resolve_fix; | 264 | struct device_node *tree_symbols, *overlay_symbols, *overlay_fixups; |
267 | struct property *rprop; | 265 | struct property *prop; |
268 | const char *refpath; | 266 | const char *refpath; |
269 | phandle phandle, phandle_delta; | 267 | phandle phandle, phandle_delta; |
270 | int err; | 268 | int err; |
271 | 269 | ||
272 | if (!resolve) | 270 | if (!overlay) |
273 | pr_err("%s: null node\n", __func__); | 271 | pr_err("%s: null overlay\n", __func__); |
274 | if (resolve && !of_node_check_flag(resolve, OF_DETACHED)) | 272 | if (overlay && !of_node_check_flag(overlay, OF_DETACHED)) |
275 | pr_err("%s: node %s not detached\n", __func__, | 273 | pr_err("%s: node %s not detached\n", __func__, |
276 | resolve->full_name); | 274 | overlay->full_name); |
277 | if (!resolve || !of_node_check_flag(resolve, OF_DETACHED)) | 275 | if (!overlay || !of_node_check_flag(overlay, OF_DETACHED)) |
278 | return -EINVAL; | 276 | return -EINVAL; |
279 | 277 | ||
280 | phandle_delta = live_tree_max_phandle() + 1; | 278 | phandle_delta = live_tree_max_phandle() + 1; |
281 | adjust_overlay_phandles(resolve, phandle_delta); | 279 | adjust_overlay_phandles(overlay, phandle_delta); |
282 | 280 | ||
283 | childroot = NULL; | 281 | local_fixups = NULL; |
284 | for_each_child_of_node(resolve, childroot) | 282 | for_each_child_of_node(overlay, local_fixups) |
285 | if (!of_node_cmp(childroot->name, "__local_fixups__")) | 283 | if (!of_node_cmp(local_fixups->name, "__local_fixups__")) |
286 | break; | 284 | break; |
287 | 285 | ||
288 | if (childroot != NULL) { | 286 | if (local_fixups != NULL) { |
289 | err = adjust_local_phandle_references(childroot, | 287 | err = adjust_local_phandle_references(local_fixups, |
290 | resolve, 0); | 288 | overlay, 0); |
291 | if (err) | 289 | if (err) |
292 | return err; | 290 | return err; |
293 | 291 | ||
294 | BUG_ON(adjust_local_phandle_references(childroot, | 292 | BUG_ON(adjust_local_phandle_references(local_fixups, |
295 | resolve, phandle_delta)); | 293 | overlay, phandle_delta)); |
296 | } | 294 | } |
297 | 295 | ||
298 | root_sym = NULL; | 296 | tree_symbols = NULL; |
299 | resolve_sym = NULL; | 297 | overlay_symbols = NULL; |
300 | resolve_fix = NULL; | 298 | overlay_fixups = NULL; |
301 | 299 | ||
302 | root_sym = of_find_node_by_path("/__symbols__"); | 300 | tree_symbols = of_find_node_by_path("/__symbols__"); |
303 | 301 | ||
304 | for_each_child_of_node(resolve, child) { | 302 | for_each_child_of_node(overlay, child) { |
305 | 303 | ||
306 | if (!resolve_sym && !of_node_cmp(child->name, "__symbols__")) | 304 | if (!overlay_symbols && !of_node_cmp(child->name, "__symbols__")) |
307 | resolve_sym = child; | 305 | overlay_symbols = child; |
308 | 306 | ||
309 | if (!resolve_fix && !of_node_cmp(child->name, "__fixups__")) | 307 | if (!overlay_fixups && !of_node_cmp(child->name, "__fixups__")) |
310 | resolve_fix = child; | 308 | overlay_fixups = child; |
311 | 309 | ||
312 | if (resolve_sym && resolve_fix) | 310 | if (overlay_symbols && overlay_fixups) |
313 | break; | 311 | break; |
314 | } | 312 | } |
315 | 313 | ||
316 | if (!resolve_fix) { | 314 | if (!overlay_fixups) { |
317 | err = 0; | 315 | err = 0; |
318 | goto out; | 316 | goto out; |
319 | } | 317 | } |
320 | 318 | ||
321 | if (!root_sym) { | 319 | if (!tree_symbols) { |
322 | pr_err("%s: no symbols in root of device tree.\n", __func__); | 320 | pr_err("%s: no symbols in root of device tree.\n", __func__); |
323 | err = -EINVAL; | 321 | err = -EINVAL; |
324 | goto out; | 322 | goto out; |
325 | } | 323 | } |
326 | 324 | ||
327 | for_each_property_of_node(resolve_fix, rprop) { | 325 | for_each_property_of_node(overlay_fixups, prop) { |
328 | 326 | ||
329 | /* skip properties added automatically */ | 327 | /* skip properties added automatically */ |
330 | if (!of_prop_cmp(rprop->name, "name")) | 328 | if (!of_prop_cmp(prop->name, "name")) |
331 | continue; | 329 | continue; |
332 | 330 | ||
333 | err = of_property_read_string(root_sym, | 331 | err = of_property_read_string(tree_symbols, |
334 | rprop->name, &refpath); | 332 | prop->name, &refpath); |
335 | if (err) | 333 | if (err) |
336 | goto out; | 334 | goto out; |
337 | 335 | ||
@@ -344,13 +342,13 @@ int of_resolve_phandles(struct device_node *resolve) | |||
344 | phandle = refnode->phandle; | 342 | phandle = refnode->phandle; |
345 | of_node_put(refnode); | 343 | of_node_put(refnode); |
346 | 344 | ||
347 | err = update_usages_of_a_phandle_reference(resolve, rprop, phandle); | 345 | err = update_usages_of_a_phandle_reference(overlay, prop, phandle); |
348 | if (err) | 346 | if (err) |
349 | break; | 347 | break; |
350 | } | 348 | } |
351 | 349 | ||
352 | out: | 350 | out: |
353 | of_node_put(root_sym); | 351 | of_node_put(tree_symbols); |
354 | 352 | ||
355 | return err; | 353 | return err; |
356 | } | 354 | } |