OF: Utility helper functions for dynamic nodes
Introduce helper functions for working with the live DT tree, all of them related to dynamically adding/removing nodes and properties. __of_prop_dup() copies a property dynamically __of_node_alloc() creates an empty node Bug fix about prop->len == 0 by Ionut Nicu <ioan.nicu.ext@nsn.com> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> [glikely: Added unittest for of_copy_property and dropped fine-grained allocations] [glikely: removed name, type and phandle arguments from __of_node_alloc] Signed-off-by: Grant Likely <grant.likely@linaro.org>
This commit is contained in:

committed by
Grant Likely

parent
6afc0dc381
commit
698433963b
@@ -16,6 +16,8 @@
|
||||
#include <linux/slab.h>
|
||||
#include <linux/device.h>
|
||||
|
||||
#include "of_private.h"
|
||||
|
||||
static struct selftest_results {
|
||||
int passed;
|
||||
int failed;
|
||||
@@ -266,6 +268,31 @@ static void __init of_selftest_property_match_string(void)
|
||||
selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc);
|
||||
}
|
||||
|
||||
#define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
|
||||
(p1)->value && (p2)->value && \
|
||||
!memcmp((p1)->value, (p2)->value, (p1)->length) && \
|
||||
!strcmp((p1)->name, (p2)->name))
|
||||
static void __init of_selftest_property_copy(void)
|
||||
{
|
||||
#ifdef CONFIG_OF_DYNAMIC
|
||||
struct property p1 = { .name = "p1", .length = 0, .value = "" };
|
||||
struct property p2 = { .name = "p2", .length = 5, .value = "abcd" };
|
||||
struct property *new;
|
||||
|
||||
new = __of_prop_dup(&p1, GFP_KERNEL);
|
||||
selftest(new && propcmp(&p1, new), "empty property didn't copy correctly\n");
|
||||
kfree(new->value);
|
||||
kfree(new->name);
|
||||
kfree(new);
|
||||
|
||||
new = __of_prop_dup(&p2, GFP_KERNEL);
|
||||
selftest(new && propcmp(&p2, new), "non-empty property didn't copy correctly\n");
|
||||
kfree(new->value);
|
||||
kfree(new->name);
|
||||
kfree(new);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void __init of_selftest_parse_interrupts(void)
|
||||
{
|
||||
struct device_node *np;
|
||||
@@ -533,6 +560,7 @@ static int __init of_selftest(void)
|
||||
of_selftest_dynamic();
|
||||
of_selftest_parse_phandle_with_args();
|
||||
of_selftest_property_match_string();
|
||||
of_selftest_property_copy();
|
||||
of_selftest_parse_interrupts();
|
||||
of_selftest_parse_interrupts_extended();
|
||||
of_selftest_match_node();
|
||||
|
Reference in New Issue
Block a user