Re: [PATCH 01/14] libfdt: fdt_offset_ptr(): Fix comparison warnings

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



On Mon, Sep 21, 2020 at 05:52:50PM +0100, Andre Przywara wrote:
> With -Wsign-compare, compilers warn about mismatching signedness in
> comparisons in fdt_offset_ptr().
> 
> This mostly stems from "offset" being passed in as a signed integer,
> even though the function would not really tolerate negative values.
> 
> Short of changing the prototype, check that offset is not negative, and
> use an unsigned type internally.
> 
> Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>

Applied, thanks.

> ---
>  libfdt/fdt.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index 37b7b93..04e1e06 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -134,16 +134,20 @@ int fdt_check_header(const void *fdt)
>  
>  const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
>  {
> -	unsigned absoffset = offset + fdt_off_dt_struct(fdt);
> +	unsigned int uoffset = offset;
> +	unsigned int absoffset = offset + fdt_off_dt_struct(fdt);
> +
> +	if (offset < 0)
> +		return NULL;
>  
>  	if (!can_assume(VALID_INPUT))
> -		if ((absoffset < offset)
> +		if ((absoffset < uoffset)
>  		    || ((absoffset + len) < absoffset)
>  		    || (absoffset + len) > fdt_totalsize(fdt))
>  			return NULL;
>  
>  	if (can_assume(LATEST) || fdt_version(fdt) >= 0x11)
> -		if (((offset + len) < offset)
> +		if (((uoffset + len) < uoffset)
>  		    || ((offset + len) > fdt_size_dt_struct(fdt)))
>  			return NULL;
>  

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