Re: [PATCH] pylibfdt: Use an unsigned type for fdt32_t

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



On Tue, Jun 12, 2018 at 11:24:11PM -0600, Simon Glass wrote:
> The members of struct fdt_header are declared as fdt32_t which is a
> 32-bit, big-endian, unsigned integer. These fields are accessed by macros
> in libfdt.h so no return type is declared. But the correct return type is
> uint32_t, not fdt32_t, since the endianness conversion is done within the
> macro before returning the value.
> 
> The macros are re-declared as normal functions in pylibfdt since swig does
> not support macros. The return type is currently int. Change it to
> uint32_t, which allows us to drop the work-around mask in Fdt.magic().
> 
> Also change the typedef for fdt32_t to uint32_t. The currently has no
> obvious effect, since use of big-endian values should always be internal
> to pylibfdt, but it is more correct.
> 
> Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx>
> Suggested-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>

Applied, thanks.

> ---
> 
>  pylibfdt/libfdt.i | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index 3abcf32..520911e 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -240,8 +240,7 @@ class Fdt:
>          Returns:
>              Magic word
>          """
> -        # Use a mask to ensure that this does not return a -ve number
> -        return fdt_magic(self._fdt) & 0xffffffff
> +        return fdt_magic(self._fdt)
>  
>      def totalsize(self):
>          """Return the total size of the device tree
> @@ -628,7 +627,11 @@ class Property(bytearray):
>  
>  %rename(fdt_property) fdt_property_func;
>  
> -typedef int fdt32_t;
> +/*
> + * fdt32_t is a big-endian 32-bit value defined to uint32_t in libfdt_env.h
> + * so use the same type here.
> + */
> +typedef uint32_t fdt32_t;
>  
>  %include "libfdt/fdt.h"
>  
> @@ -716,15 +719,15 @@ typedef int fdt32_t;
>  %warnfilter(302) fdt_property;
>  
>  /* These are macros in the header so have to be redefined here */
> -int fdt_magic(const void *fdt);
> -int fdt_totalsize(const void *fdt);
> -int fdt_off_dt_struct(const void *fdt);
> -int fdt_off_dt_strings(const void *fdt);
> -int fdt_off_mem_rsvmap(const void *fdt);
> -int fdt_version(const void *fdt);
> -int fdt_last_comp_version(const void *fdt);
> -int fdt_boot_cpuid_phys(const void *fdt);
> -int fdt_size_dt_strings(const void *fdt);
> -int fdt_size_dt_struct(const void *fdt);
> +uint32_t fdt_magic(const void *fdt);
> +uint32_t fdt_totalsize(const void *fdt);
> +uint32_t fdt_off_dt_struct(const void *fdt);
> +uint32_t fdt_off_dt_strings(const void *fdt);
> +uint32_t fdt_off_mem_rsvmap(const void *fdt);
> +uint32_t fdt_version(const void *fdt);
> +uint32_t fdt_last_comp_version(const void *fdt);
> +uint32_t fdt_boot_cpuid_phys(const void *fdt);
> +uint32_t fdt_size_dt_strings(const void *fdt);
> +uint32_t fdt_size_dt_struct(const void *fdt);
>  
>  %include <../libfdt/libfdt.h>

-- 
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