[PATCH 08/10] mfd: atmel-smc: Silence comparison of unsigned expression < 0 is always false warning (W=1)

Lee Jones lee.jones at linaro.org
Tue Jun 30 08:10:23 EDT 2020

On Fri, 26 Jun 2020, Alexandre Belloni wrote:

> Hi,
> On 25/06/2020 07:46:17+0100, Lee Jones wrote:
> > GENMASK and it's callees conduct checking to ensure the passed
> > parameters are valid.  One of those checks is for '< 0'.  So if an
> > unsigned value is passed, in an invalid comparison takes place.
> > 
> > Judging from the current code, it looks as though 'unsigned int'
> > is the correct type to use, so simply cast these small values
> > with no chance of being false negative to signed int for
> > comparison/error checking purposes.
> > 
> I've been thinking about that one but shouldn't the proper fix be in
> GENMASK? My understanding is that this happens because l is 0 and I
> don't think GENMASK would ever expect negative number. What about simply
> checking that h != l when l is 0?

Looks like Rikard Falkeborn recently submitted a patch to 'fix' this
issue.  However, Linus slammed it, decrying that it's the warning
that's wrong, not the code.  Looks like the type-limits warning might
be getting downgraded to W=2 instead (although I don't see a patch

I'm going to drop this patch.

Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

More information about the linux-arm-kernel mailing list