stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Lee Jones <lee.jones@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	Boris Brezillon <boris.brezillon@free-electrons.com>
Subject: Re: [PATCH 08/10] mfd: atmel-smc: Silence comparison of unsigned expression < 0 is always false warning (W=1)
Date: Fri, 26 Jun 2020 22:56:27 +0200	[thread overview]
Message-ID: <20200626205627.GU131826@piout.net> (raw)
In-Reply-To: <20200625064619.2775707-9-lee.jones@linaro.org>

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?

> Squashes the following W=1 warnings:
> 
>  In file included from /home/lee/projects/linux/kernel/include/linux/bits.h:23,
>  from /home/lee/projects/linux/kernel/include/linux/bitops.h:5,
>  from /home/lee/projects/linux/kernel/include/linux/kernel.h:12,
>  from /home/lee/projects/linux/kernel/include/linux/mfd/syscon/atmel-smc.h:14,
>  from /home/lee/projects/linux/kernel/drivers/mfd/atmel-smc.c:11:
>  /home/lee/projects/linux/kernel/drivers/mfd/atmel-smc.c: In function ‘atmel_smc_cs_encode_ncycles’:
>  /home/lee/projects/linux/kernel/include/linux/bits.h:26:28: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
>  26 | __builtin_constant_p((l) > (h)), (l) > (h), 0)))
>  | ^
>  /home/lee/projects/linux/kernel/include/linux/build_bug.h:16:62: note: in definition of macro ‘BUILD_BUG_ON_ZERO’
>  16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
>  | ^
>  /home/lee/projects/linux/kernel/include/linux/bits.h:39:3: note: in expansion of macro ‘GENMASK_INPUT_CHECK’
>  39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
>  | ^~~~~~~~~~~~~~~~~~~
>  /home/lee/projects/linux/kernel/drivers/mfd/atmel-smc.c:49:25: note: in expansion of macro ‘GENMASK’
>  49 | unsigned int lsbmask = GENMASK(msbpos - 1, 0);
>  | ^~~~~~~
>  /home/lee/projects/linux/kernel/include/linux/bits.h:26:40: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
>  26 | __builtin_constant_p((l) > (h)), (l) > (h), 0)))
>  | ^
>  /home/lee/projects/linux/kernel/include/linux/build_bug.h:16:62: note: in definition of macro ‘BUILD_BUG_ON_ZERO’
>  16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
>  | ^
>  /home/lee/projects/linux/kernel/include/linux/bits.h:39:3: note: in expansion of macro ‘GENMASK_INPUT_CHECK’
>  39 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
>  | ^~~~~~~~~~~~~~~~~~~
> 
> Cc: <stable@vger.kernel.org>
> Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Ludovic Desroches <ludovic.desroches@microchip.com>
> Cc: Boris Brezillon <boris.brezillon@free-electrons.com>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  drivers/mfd/atmel-smc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/atmel-smc.c b/drivers/mfd/atmel-smc.c
> index 1fa2ec950e7df..17bbe9d1fa740 100644
> --- a/drivers/mfd/atmel-smc.c
> +++ b/drivers/mfd/atmel-smc.c
> @@ -46,8 +46,8 @@ static int atmel_smc_cs_encode_ncycles(unsigned int ncycles,
>  				       unsigned int msbfactor,
>  				       unsigned int *encodedval)
>  {
> -	unsigned int lsbmask = GENMASK(msbpos - 1, 0);
> -	unsigned int msbmask = GENMASK(msbwidth - 1, 0);
> +	unsigned int lsbmask = GENMASK((int)msbpos - 1, 0);
> +	unsigned int msbmask = GENMASK((int)msbwidth - 1, 0);
>  	unsigned int msb, lsb;
>  	int ret = 0;
>  
> -- 
> 2.25.1
> 

-- 
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2020-06-26 20:56 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200625064619.2775707-1-lee.jones@linaro.org>
2020-06-25  6:46 ` [PATCH 01/10] mfd: wm8350-core: Supply description wm8350_reg_{un}lock args Lee Jones
2020-06-25  6:56   ` Greg KH
2020-06-25  7:13     ` Lee Jones
2020-06-25  9:45       ` Greg KH
2020-06-25 13:34         ` Lee Jones
2020-06-25 13:24       ` Jonathan Corbet
2020-06-25 13:38         ` Lee Jones
2020-06-25  6:46 ` [PATCH 02/10] mfd: mfd-core: Complete kerneldoc header for devm_mfd_add_devices() Lee Jones
2020-07-01 19:33   ` Sasha Levin
2020-07-02  6:36     ` Lee Jones
2020-07-10 14:02   ` Sasha Levin
2020-06-25  6:46 ` [PATCH 03/10] mfd: db8500-prcmu: Add description for 'reset_reason' in kerneldoc Lee Jones
2020-07-07 12:39   ` Linus Walleij
2020-06-25  6:46 ` [PATCH 04/10] mfd: db8500-prcmu: Remove incorrect function header from .probe() function Lee Jones
2020-07-07 12:39   ` Linus Walleij
2020-06-25  6:46 ` [PATCH 05/10] mfd: omap-usb-host: Remove invalid use of kerneldoc syntax Lee Jones
2020-06-25  6:46 ` [PATCH 06/10] mfd: omap-usb-host: Provide description for 'pdev' argument to .probe() Lee Jones
2020-06-25  6:46 ` [PATCH 07/10] mfd: omap-usb-tll: " Lee Jones
2020-06-25  6:46 ` [PATCH 08/10] mfd: atmel-smc: Silence comparison of unsigned expression < 0 is always false warning (W=1) Lee Jones
2020-06-26 20:56   ` Alexandre Belloni [this message]
2020-06-30 12:10     ` Lee Jones
2020-06-25  6:46 ` [PATCH 09/10] mfd: atmel-smc: Add missing colon(s) for 'conf' arguments Lee Jones
2020-06-25  6:55   ` Greg KH
2020-06-26 20:56   ` Alexandre Belloni
2020-07-01 19:33   ` Sasha Levin
2020-07-02  6:36     ` Lee Jones
2020-07-10 14:02   ` Sasha Levin
2020-06-25  6:46 ` [PATCH 10/10] mfd: altera-sysmgr: Supply descriptions for 'np' and 'property' function args Lee Jones
2020-07-01 19:33   ` Sasha Levin
2020-07-02  6:35     ` Lee Jones
2020-07-10 14:02   ` Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200626205627.GU131826@piout.net \
    --to=alexandre.belloni@bootlin.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).