of/selftest: Use the resolver to fixup phandles
authorGrant Likely <grant.likely@linaro.org>
Thu, 2 Oct 2014 13:36:46 +0000 (14:36 +0100)
committerGrant Likely <grant.likely@linaro.org>
Sat, 4 Oct 2014 20:24:35 +0000 (21:24 +0100)
The selftest data ends up causing duplicate phandles in the live tree
for the time that the testcase data is inserted into the live tree. This
is obviously a bad situation because anything attempting to read the
tree while the selftests are running make resolve phandles to one of the
testcase data nodes. Fix the problem by using the of_resolve_phandles()
function to eliminate duplicates.

Signed-off-by: Grant Likely <grant.likely@linaro.org>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Gaurav Minocha <gaurav.minocha.os@gmail.com>
drivers/of/Kconfig
drivers/of/selftest.c
drivers/of/testcase-data/testcases.dts

index 6b81a36f6420802bccfd8125968d278609ea6b3c..1a13f5b722c57e4d2d523c6be9b289084dba115a 100644 (file)
@@ -11,6 +11,7 @@ config OF_SELFTEST
        bool "Device Tree Runtime self tests"
        depends on OF_IRQ && OF_EARLY_FLATTREE
        select OF_DYNAMIC
+       select OF_RESOLVE
        help
          This option builds in test cases for the device tree infrastructure
          that are executed once at boot time, and the results dumped to the
index 4f83e97f878856fa98b6c0215466cf680e47a309..4fed34bff5cf736cdf2dd6d998222dee1b1b52d2 100644 (file)
@@ -25,7 +25,7 @@ static struct selftest_results {
        int failed;
 } selftest_results;
 
-#define NO_OF_NODES 2
+#define NO_OF_NODES 3
 static struct device_node *nodes[NO_OF_NODES];
 static int last_node_index;
 static bool selftest_live_tree;
@@ -765,6 +765,7 @@ static int __init selftest_data_add(void)
        extern uint8_t __dtb_testcases_begin[];
        extern uint8_t __dtb_testcases_end[];
        const int size = __dtb_testcases_end - __dtb_testcases_begin;
+       int rc;
 
        if (!size) {
                pr_warn("%s: No testcase data to attach; not running tests\n",
@@ -785,6 +786,12 @@ static int __init selftest_data_add(void)
                pr_warn("%s: No tree to attach; not running tests\n", __func__);
                return -ENODATA;
        }
+       of_node_set_flag(selftest_data_node, OF_DETACHED);
+       rc = of_resolve_phandles(selftest_data_node);
+       if (rc) {
+               pr_err("%s: Failed to resolve phandles (rc=%i)\n", __func__, rc);
+               return -EINVAL;
+       }
 
        if (!of_allnodes) {
                /* enabling flag for removing nodes */
index 219ef9324e9c6b8e270f064b97a1d34f11e6c884..6994e15c24bfe25d322ec9fe499daef23084a3bb 100644 (file)
 #include "tests-interrupts.dtsi"
 #include "tests-match.dtsi"
 #include "tests-platform.dtsi"
+
+/*
+ * phandle fixup data - generated by dtc patches that aren't upstream.
+ * This data must be regenerated whenever phandle references are modified in
+ * the testdata tree.
+ *
+ * The format of this data may be subject to change. For the time being consider
+ * this a kernel-internal data format.
+ */
+/ { __local_fixups__ {
+       fixup = "/testcase-data/testcase-device2:interrupt-parent:0",
+               "/testcase-data/testcase-device1:interrupt-parent:0",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:60",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:52",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:44",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:36",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:24",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:8",
+               "/testcase-data/interrupts/interrupts-extended0:interrupts-extended:0",
+               "/testcase-data/interrupts/interrupts1:interrupt-parent:0",
+               "/testcase-data/interrupts/interrupts0:interrupt-parent:0",
+               "/testcase-data/interrupts/intmap1:interrupt-map:12",
+               "/testcase-data/interrupts/intmap0:interrupt-map:52",
+               "/testcase-data/interrupts/intmap0:interrupt-map:36",
+               "/testcase-data/interrupts/intmap0:interrupt-map:16",
+               "/testcase-data/interrupts/intmap0:interrupt-map:4",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:12",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list-bad-args:0",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list:56",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list:52",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list:40",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list:24",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list:8",
+               "/testcase-data/phandle-tests/consumer-a:phandle-list:0";
+}; };