aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@linaro.org>2014-11-14 10:33:07 -0500
committerGrant Likely <grant.likely@linaro.org>2014-11-24 17:23:35 -0500
commitef8bbd73a76197cf8362a2b43aaadc5717bd0746 (patch)
tree85e5d8b9e98a1d7c2ac6c42e698dec4ac21a98b8
parent66e6a5a1fcd2f3e05f4d499b539a1f77ceb52d1d (diff)
of: Use vargs in __of_node_alloc
The overlay code needs to construct a new full_name from the parent name and the node name, but the current method has to allocate and then free an temporary string which is wasteful. Fix this problem by using vargs to pass in a format and arguments into __of_node_alloc(). At the same time remove the allocflags argument to __of_node_alloc(). The only users all use GFP_KERNEL, so there is no need to provide it as an option. If there is ever a need later it can be added back. Signed-off-by: Grant Likely <grant.likely@linaro.org>
-rw-r--r--drivers/of/dynamic.c16
-rw-r--r--drivers/of/of_private.h2
-rw-r--r--drivers/of/unittest.c6
3 files changed, 12 insertions, 12 deletions
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index d43f3059963b..af1b1ecd6a3d 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -274,33 +274,33 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
274/** 274/**
275 * __of_node_alloc() - Create an empty device node dynamically. 275 * __of_node_alloc() - Create an empty device node dynamically.
276 * @full_name: Full name of the new device node 276 * @full_name: Full name of the new device node
277 * @allocflags: Allocation flags (typically pass GFP_KERNEL)
278 * 277 *
279 * Create an empty device tree node, suitable for further modification. 278 * Create an empty device tree node, suitable for further modification.
280 * The node data are dynamically allocated and all the node flags 279 * The node data are dynamically allocated and all the node flags
281 * have the OF_DYNAMIC & OF_DETACHED bits set. 280 * have the OF_DYNAMIC & OF_DETACHED bits set.
282 * Returns the newly allocated node or NULL on out of memory error. 281 * Returns the newly allocated node or NULL on out of memory error.
283 */ 282 */
284struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags) 283struct device_node *__of_node_alloc(const char *fmt, ...)
285{ 284{
285 va_list vargs;
286 struct device_node *node; 286 struct device_node *node;
287 287
288 node = kzalloc(sizeof(*node), allocflags); 288 node = kzalloc(sizeof(*node), GFP_KERNEL);
289 if (!node) 289 if (!node)
290 return NULL; 290 return NULL;
291 291 va_start(vargs, fmt);
292 node->full_name = kstrdup(full_name, allocflags); 292 node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs);
293 of_node_set_flag(node, OF_DYNAMIC); 293 va_end(vargs);
294 of_node_set_flag(node, OF_DETACHED);
295 if (!node->full_name) 294 if (!node->full_name)
296 goto err_free; 295 goto err_free;
297 296
297 of_node_set_flag(node, OF_DYNAMIC);
298 of_node_set_flag(node, OF_DETACHED);
298 of_node_init(node); 299 of_node_init(node);
299 300
300 return node; 301 return node;
301 302
302 err_free: 303 err_free:
303 kfree(node->full_name);
304 kfree(node); 304 kfree(node);
305 return NULL; 305 return NULL;
306} 306}
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
index 858e0a5d9a11..618abcad307e 100644
--- a/drivers/of/of_private.h
+++ b/drivers/of/of_private.h
@@ -61,7 +61,7 @@ static inline int of_property_notify(int action, struct device_node *np,
61 * own the devtree lock or work on detached trees only. 61 * own the devtree lock or work on detached trees only.
62 */ 62 */
63struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags); 63struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
64struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags); 64__printf(1, 2) struct device_node *__of_node_alloc(const char *fmt, ...);
65 65
66extern const void *__of_get_property(const struct device_node *np, 66extern const void *__of_get_property(const struct device_node *np,
67 const char *name, int *lenp); 67 const char *name, int *lenp);
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 46af7019d291..7634a17af1d5 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -449,11 +449,11 @@ static void __init of_selftest_changeset(void)
449 struct of_changeset chgset; 449 struct of_changeset chgset;
450 450
451 of_changeset_init(&chgset); 451 of_changeset_init(&chgset);
452 n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL); 452 n1 = __of_node_alloc("/testcase-data/changeset/n1");
453 selftest(n1, "testcase setup failure\n"); 453 selftest(n1, "testcase setup failure\n");
454 n2 = __of_node_alloc("/testcase-data/changeset/n2", GFP_KERNEL); 454 n2 = __of_node_alloc("/testcase-data/changeset/n2");
455 selftest(n2, "testcase setup failure\n"); 455 selftest(n2, "testcase setup failure\n");
456 n21 = __of_node_alloc("/testcase-data/changeset/n2/n21", GFP_KERNEL); 456 n21 = __of_node_alloc("/testcase-data/changeset/n2/n21");
457 selftest(n21, "testcase setup failure %p\n", n21); 457 selftest(n21, "testcase setup failure %p\n", n21);
458 nremove = of_find_node_by_path("/testcase-data/changeset/node-remove"); 458 nremove = of_find_node_by_path("/testcase-data/changeset/node-remove");
459 selftest(nremove, "testcase setup failure\n"); 459 selftest(nremove, "testcase setup failure\n");