Skip to content

Commit ef8bbd7

Browse files
committed
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>
1 parent 66e6a5a commit ef8bbd7

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎drivers/of/dynamic.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,33 +274,33 @@ struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags)
274274
/**
275275
* __of_node_alloc() - Create an empty device node dynamically.
276276
* @full_name: Full name of the new device node
277-
* @allocflags: Allocation flags (typically pass GFP_KERNEL)
278277
*
279278
* Create an empty device tree node, suitable for further modification.
280279
* The node data are dynamically allocated and all the node flags
281280
* have the OF_DYNAMIC & OF_DETACHED bits set.
282281
* Returns the newly allocated node or NULL on out of memory error.
283282
*/
284-
struct device_node *__of_node_alloc(const char *full_name, gfp_t allocflags)
283+
struct device_node *__of_node_alloc(const char *fmt, ...)
285284
{
285+
va_list vargs;
286286
struct device_node *node;
287287

288-
node = kzalloc(sizeof(*node), allocflags);
288+
node = kzalloc(sizeof(*node), GFP_KERNEL);
289289
if (!node)
290290
return NULL;
291-
292-
node->full_name = kstrdup(full_name, allocflags);
293-
of_node_set_flag(node, OF_DYNAMIC);
294-
of_node_set_flag(node, OF_DETACHED);
291+
va_start(vargs, fmt);
292+
node->full_name = kvasprintf(GFP_KERNEL, fmt, vargs);
293+
va_end(vargs);
295294
if (!node->full_name)
296295
goto err_free;
297296

297+
of_node_set_flag(node, OF_DYNAMIC);
298+
of_node_set_flag(node, OF_DETACHED);
298299
of_node_init(node);
299300

300301
return node;
301302

302303
err_free:
303-
kfree(node->full_name);
304304
kfree(node);
305305
return NULL;
306306
}

‎drivers/of/of_private.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static inline int of_property_notify(int action, struct device_node *np,
6161
* own the devtree lock or work on detached trees only.
6262
*/
6363
struct property *__of_prop_dup(const struct property *prop, gfp_t allocflags);
64-
struct 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, ...);
6565

6666
extern const void *__of_get_property(const struct device_node *np,
6767
const char *name, int *lenp);

‎drivers/of/unittest.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ static void __init of_selftest_changeset(void)
449449
struct of_changeset chgset;
450450

451451
of_changeset_init(&chgset);
452-
n1 = __of_node_alloc("/testcase-data/changeset/n1", GFP_KERNEL);
452+
n1 = __of_node_alloc("/testcase-data/changeset/n1");
453453
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");
455455
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");
457457
selftest(n21, "testcase setup failure %p\n", n21);
458458
nremove = of_find_node_by_path("/testcase-data/changeset/node-remove");
459459
selftest(nremove, "testcase setup failure\n");

0 commit comments

Comments
 (0)