Re: [PATCH] pylibfdt: Update the bytearray size with pack()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Wed, Jun 13, 2018 at 05:38:23AM -0600, Simon Glass wrote:
> 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 <sjg@xxxxxxxxxxxx>

Applied, thanks.

> ---
> 
>  pylibfdt/libfdt.i       | 9 ++++++++-
>  tests/pylibfdt_tests.py | 1 +
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index adb4ee8..c0a2191 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -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
> diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
> index 0467375..c9653a5 100644
> --- a/tests/pylibfdt_tests.py
> +++ b/tests/pylibfdt_tests.py
> @@ -308,6 +308,7 @@ class PyLibfdtTests(unittest.TestCase):
>          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"""

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux