Re: [PATCH 09/14] libfdt: fdt_resize(): Fix comparison warning

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



On Mon, Sep 21, 2020 at 05:52:58PM +0100, Andre Przywara wrote:
> With -Wsign-compare, compilers warn about a mismatching signedness
> in a comparison in fdt_resize().
> 
> A negative buffer size will surely do us no good, so let's rule this
> case out first.
> In the actual comparison we then know that a cast to an unsigned type is
> safe.
> 
> Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>

Applied, thanks.

> ---
>  libfdt/fdt_sw.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libfdt/fdt_sw.c b/libfdt/fdt_sw.c
> index 8a76adf..4c62922 100644
> --- a/libfdt/fdt_sw.c
> +++ b/libfdt/fdt_sw.c
> @@ -152,6 +152,9 @@ int fdt_resize(void *fdt, void *buf, int bufsize)
>  
>  	FDT_SW_PROBE(fdt);
>  
> +	if (bufsize < 0)
> +		return -FDT_ERR_NOSPACE;
> +
>  	headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt);
>  	tailsize = fdt_size_dt_strings(fdt);
>  
> @@ -159,7 +162,7 @@ int fdt_resize(void *fdt, void *buf, int bufsize)
>  	    headsize + tailsize > fdt_totalsize(fdt))
>  		return -FDT_ERR_INTERNAL;
>  
> -	if ((headsize + tailsize) > bufsize)
> +	if ((headsize + tailsize) > (unsigned)bufsize)
>  		return -FDT_ERR_NOSPACE;
>  
>  	oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize;

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