From: =?UTF-8?Q?Andr=c3=a9_Przywara?= Subject: Re: [PATCH 14/14] libfdt: fdt_strerror(): Fix comparison warning Date: Thu, 1 Oct 2020 16:34:01 +0100 Message-ID: <3ede218a-e0c8-e86a-b523-cbd07b590048@arm.com> References: <20200921165303.9115-1-andre.przywara@arm.com> <20200921165303.9115-15-andre.przywara@arm.com> <20200925041208.GZ2298@yekko.fritz.box> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20200925041208.GZ2298-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org> Content-Language: en-GB List-ID: Content-Type: text/plain; charset="us-ascii" To: David Gibson Cc: Simon Glass , Devicetree Compiler , Varun Wadekar 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 > > 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 ""; >> else if (errval == 0) >> return ""; >> - else if (errval > -FDT_ERRTABSIZE) { >> + else if (errval > -(int)FDT_ERRTABSIZE) { >> const char *s = fdt_errtable[-errval].str; >> >> if (s) >