Skip to content

Commit

Permalink
pylibfdt: Update the bytearray size with pack()
Browse files Browse the repository at this point in the history
At present pack() calls fdt_pack() which may well reduce the size of the
device-tree data. However this does not currently update the size of the
bytearray to take account of any reduction. This means that there may be
unused data at the end of the bytearray and any users of as_bytearray()
will see this extra data.

Fix this by resizing the bytearray after packing.

Signed-off-by: Simon Glass <[email protected]>
Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
sjg20 authored and dgibson committed Jun 13, 2018
1 parent 3c374d4 commit 354d3dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pylibfdt/libfdt.i
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,17 @@ class Fdt:
Args:
quiet: Errors to ignore (empty to raise on all errors)

Returns:
Error code, or 0 if OK

Raises:
FdtException if any error occurs
"""
return check_err(fdt_pack(self._fdt), quiet)
err = check_err(fdt_pack(self._fdt), quiet)
if err:
return err
del self._fdt[self.totalsize():]
return err

def getprop(self, nodeoffset, prop_name, quiet=()):
"""Get a property from a node
Expand Down
1 change: 1 addition & 0 deletions tests/pylibfdt_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def testPack(self):
self.assertEquals(orig_size, self.fdt.totalsize())
self.assertEquals(self.fdt.pack(), 0)
self.assertTrue(self.fdt.totalsize() < orig_size)
self.assertEquals(self.fdt.totalsize(), len(self.fdt.as_bytearray()))

def testBadPropertyOffset(self):
"""Test that bad property offsets are detected"""
Expand Down

0 comments on commit 354d3dc

Please sign in to comment.