]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Fix Fdt.GetNode() to handle a missing node
authorSimon Glass <sjg@chromium.org>
Fri, 6 Jul 2018 16:27:30 +0000 (10:27 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 9 Jul 2018 15:11:00 +0000 (09:11 -0600)
At present the algortihm is not correct since it will return the root node
if the requested node is not found and there are no slashes in the
requested node name. Fix this and add a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/fdt.py
tools/dtoc/test_fdt.py

index 274c142e7ae55fab88b92896fba6ab92c12adc35..c1d04d48e889699159e38576d76c53db75fe2b93 100644 (file)
@@ -318,7 +318,10 @@ class Fdt:
             Node object, or None if not found
         """
         node = self._root
-        for part in path.split('/')[1:]:
+        parts = path.split('/')
+        if len(parts) < 2:
+            return None
+        for part in parts[1:]:
             node = node._FindNode(part)
             if not node:
                 return None
index e57298dbe7cd4d22e83cf42138bb444462c0985e..9fef8ed5496ec0bcae2ab8732eac531d6265623f 100755 (executable)
@@ -205,6 +205,9 @@ class TestProp(unittest.TestCase):
         self.node = self.dtb.GetNode('/spl-test')
         self.fdt = self.dtb.GetFdtObj()
 
+    def testMissingNode(self):
+        self.assertEqual(None, self.dtb.GetNode('missing'))
+
     def testPhandle(self):
         dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts')
         node = dtb.GetNode('/phandle-source')