Re: [PATCH v2 5/6] libfdt: fdt_get_string(): Fix sequential write comparison warnings

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



On Thu, Oct 01, 2020 at 05:46:29PM +0100, Andre Przywara wrote:
> With -Wsign-compare, compilers warn about a mismatching signedness in
> comparisons in fdt_get_string().
> 
> Introduce a new usigned variable, which holds the actual (negated)
> stroffset value, so we avoid negating all the other variables and have
> proper types everywhere.
> 
> Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>

Applied, thanks.

> ---
>  libfdt/fdt_ro.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index e192184..91cc6fe 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -67,11 +67,13 @@ const char *fdt_get_string(const void *fdt, int stroffset, int *lenp)
>  				len = fdt_size_dt_strings(fdt) - stroffset;
>  		}
>  	} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
> -		if ((stroffset >= 0)
> -		    || (stroffset < -fdt_size_dt_strings(fdt)))
> +		unsigned int sw_stroffset = -stroffset;
> +
> +		if ((stroffset >= 0) ||
> +		    (sw_stroffset > fdt_size_dt_strings(fdt)))
>  			goto fail;
> -		if ((-stroffset) < len)
> -			len = -stroffset;
> +		if (sw_stroffset < len)
> +			len = sw_stroffset;
>  	} else {
>  		err = -FDT_ERR_INTERNAL;
>  		goto fail;

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