lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200625064619.2775707-9-lee.jones@linaro.org>
Date:   Thu, 25 Jun 2020 07:46:17 +0100
From:   Lee Jones <lee.jones@...aro.org>
To:     lee.jones@...aro.org
Cc:     linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        stable@...r.kernel.org,
        Nicolas Ferre <nicolas.ferre@...rochip.com>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>,
        Ludovic Desroches <ludovic.desroches@...rochip.com>,
        Boris Brezillon <boris.brezillon@...e-electrons.com>
Subject: [PATCH 08/10] mfd: atmel-smc: Silence comparison of unsigned expression < 0 is always false warning (W=1)

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.

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@...r.kernel.org>
Cc: Nicolas Ferre <nicolas.ferre@...rochip.com>
Cc: Alexandre Belloni <alexandre.belloni@...tlin.com>
Cc: Ludovic Desroches <ludovic.desroches@...rochip.com>
Cc: Boris Brezillon <boris.brezillon@...e-electrons.com>
Signed-off-by: Lee Jones <lee.jones@...aro.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ