Skip to content

Commit

Permalink
pylibfdt: add size_hint parameter for get_path
Browse files Browse the repository at this point in the history
This also enables us to test the -NOSPACE condition by adding a test
setting size_hint=1 so this path is taken.

Message-Id: <[email protected]>
Signed-off-by: Luca Weiss <[email protected]>
Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
z3ntu authored and dgibson committed Feb 5, 2023
1 parent abbd523 commit 3f29d6d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pylibfdt/libfdt.i
Original file line number Diff line number Diff line change
Expand Up @@ -443,23 +443,23 @@ class FdtRo(object):
"""
return fdt_get_alias(self._fdt, name)

def get_path(self, nodeoffset, quiet=()):
def get_path(self, nodeoffset, size_hint=1024, quiet=()):
"""Get the full path of a node
Args:
nodeoffset: Node offset to check
size_hint: Hint for size of returned string
Returns:
Full path to the node
Raises:
FdtException if an error occurs
"""
size = 1024
while True:
ret, path = fdt_get_path(self._fdt, nodeoffset, size)
ret, path = fdt_get_path(self._fdt, nodeoffset, size_hint)
if ret == -NOSPACE:
size = size * 2
size_hint *= 2
continue
err = check_err(ret, quiet)
if err:
Expand Down
1 change: 1 addition & 0 deletions tests/pylibfdt_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ def testGetPath(self):
node2 = self.fdt.path_offset('/subnode@1/subsubnode')
self.assertEqual("/subnode@1", self.fdt.get_path(node))
self.assertEqual("/subnode@1/subsubnode", self.fdt.get_path(node2))
self.assertEqual("/subnode@1/subsubnode", self.fdt.get_path(node2, size_hint=1))

with self.assertRaises(FdtException) as e:
self.fdt.get_path(-1)
Expand Down

0 comments on commit 3f29d6d

Please sign in to comment.