diff options
author | Pantelis Antoniou <pantelis.antoniou@konsulko.com> | 2014-07-04 18:58:47 +0200 |
---|---|---|
committer | Grant Likely <grant.likely@linaro.org> | 2014-07-16 16:16:17 +0200 |
commit | 698433963b98d6de7b102c242805c99fda4fa1fb (patch) | |
tree | 05a223f160742f6659e47cd5accc245934c941ef /drivers/of/selftest.c | |
parent | of: Move CONFIG_OF_DYNAMIC code into a separate file (diff) | |
download | linux-698433963b98d6de7b102c242805c99fda4fa1fb.tar.xz linux-698433963b98d6de7b102c242805c99fda4fa1fb.zip |
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>
Diffstat (limited to 'drivers/of/selftest.c')
-rw-r--r-- | drivers/of/selftest.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 077314eebb95..ee2166f0f36a 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -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(); |