aboutsummaryrefslogtreecommitdiff
path: root/drivers/of/selftest.c
diff options
context:
space:
mode:
authorPantelis Antoniou <pantelis.antoniou@konsulko.com>2014-07-04 19:58:47 +0300
committerMark Brown <broonie@kernel.org>2015-02-19 23:30:21 +0900
commita39492cbb90cebc0c1cb55d95e913848f6d68109 (patch)
tree3e0f9f5753bd33930758859564ab562e105ed315 /drivers/of/selftest.c
parentd5ba7b3ca35a9cb01680fac0e249ad6e12b56389 (diff)
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> (cherry picked from commit 698433963b98d6de7b102c242805c99fda4fa1fb) Signed-off-by: Mark Brown <broonie@kernel.org> Conflicts: drivers/of/of_private.h
Diffstat (limited to 'drivers/of/selftest.c')
-rw-r--r--drivers/of/selftest.c28
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();