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

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



On 25/09/2020 05:12, David Gibson wrote:
> On Mon, Sep 21, 2020 at 05:53:03PM +0100, Andre Przywara wrote:
>> With -Wsign-compare, compilers warn about a mismatching signedness
>> in a comparison in fdt_strerror().
>>
>> At this point we are sure that errval is negative, and since
>> FDT_ERRTABSIZE is surely positive, we can do some casting to make the
>> compiler happy.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>
> 
> Since error values are typically conveyed as negative numbers (which
> is kind of the whole reason we have all these signed values in the
> first place), I think it would be slightly nicer to actually fold the
> case to signed into the definition of FDT_ERRTABSIZE.

Right, makes more sense. I changed the comparison to:
	if (-errval < FDT_ERRTABSIZE)
which is more in line with what we actually do below.

Cheers,
Andre

>> ---
>>  libfdt/fdt_strerror.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libfdt/fdt_strerror.c b/libfdt/fdt_strerror.c
>> index 768db66..efce51d 100644
>> --- a/libfdt/fdt_strerror.c
>> +++ b/libfdt/fdt_strerror.c
>> @@ -48,7 +48,7 @@ const char *fdt_strerror(int errval)
>>  		return "<valid offset/length>";
>>  	else if (errval == 0)
>>  		return "<no error>";
>> -	else if (errval > -FDT_ERRTABSIZE) {
>> +	else if (errval > -(int)FDT_ERRTABSIZE) {
>>  		const char *s = fdt_errtable[-errval].str;
>>  
>>  		if (s)
> 




[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