kernel.h: Silence sparse warning in lower_32_bits
diff mbox series

Message ID 20200828071125.GA18772@gondor.apana.org.au
State Accepted
Commit ef91bb196b0db1013ef8705367bc2d7944ef696b
Headers show
Series
  • kernel.h: Silence sparse warning in lower_32_bits
Related show

Commit Message

Herbert Xu Aug. 28, 2020, 7:11 a.m. UTC
I keep getting sparse warnings in crypto such as:

  CHECK   ../drivers/crypto/ccree/cc_hash.c
../drivers/crypto/ccree/cc_hash.c:49:9: warning: cast truncates bits from constant value (47b5481dbefa4fa4 becomes befa4fa4)
../drivers/crypto/ccree/cc_hash.c:49:26: warning: cast truncates bits from constant value (db0c2e0d64f98fa7 becomes 64f98fa7)
../drivers/crypto/ccree/cc_hash.c:49:43: warning: cast truncates bits from constant value (8eb44a8768581511 becomes 68581511)
../drivers/crypto/ccree/cc_hash.c:49:60: warning: cast truncates bits from constant value (67332667ffc00b31 becomes ffc00b31)
../drivers/crypto/ccree/cc_hash.c:50:9: warning: cast truncates bits from constant value (152fecd8f70e5939 becomes f70e5939)
../drivers/crypto/ccree/cc_hash.c:50:26: warning: cast truncates bits from constant value (9159015a3070dd17 becomes 3070dd17)
../drivers/crypto/ccree/cc_hash.c:50:43: warning: cast truncates bits from constant value (629a292a367cd507 becomes 367cd507)
../drivers/crypto/ccree/cc_hash.c:50:60: warning: cast truncates bits from constant value (cbbb9d5dc1059ed8 becomes c1059ed8)
../drivers/crypto/ccree/cc_hash.c:52:9: warning: cast truncates bits from constant value (5be0cd19137e2179 becomes 137e2179)
../drivers/crypto/ccree/cc_hash.c:52:26: warning: cast truncates bits from constant value (1f83d9abfb41bd6b becomes fb41bd6b)
../drivers/crypto/ccree/cc_hash.c:52:43: warning: cast truncates bits from constant value (9b05688c2b3e6c1f becomes 2b3e6c1f)
../drivers/crypto/ccree/cc_hash.c:52:60: warning: cast truncates bits from constant value (510e527fade682d1 becomes ade682d1)
../drivers/crypto/ccree/cc_hash.c:53:9: warning: cast truncates bits from constant value (a54ff53a5f1d36f1 becomes 5f1d36f1)
../drivers/crypto/ccree/cc_hash.c:53:26: warning: cast truncates bits from constant value (3c6ef372fe94f82b becomes fe94f82b)
../drivers/crypto/ccree/cc_hash.c:53:43: warning: cast truncates bits from constant value (bb67ae8584caa73b becomes 84caa73b)
../drivers/crypto/ccree/cc_hash.c:53:60: warning: cast truncates bits from constant value (6a09e667f3bcc908 becomes f3bcc908)

This patch removes the warning by adding a mask to keep sparse
happy.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Guenter Roeck Aug. 29, 2020, 10:51 a.m. UTC | #1
On Fri, Aug 28, 2020 at 05:11:25PM +1000, Herbert Xu wrote:
> I keep getting sparse warnings in crypto such as:
> 

This patch results in the following compile error when compiling 
ppc:mpc85xx_defconfig.

Error log:
In file included from ./include/linux/list.h:9,
                 from ./include/linux/module.h:12,
                 from drivers/dma/fsldma.c:23:
drivers/dma/fsldma.h: In function 'fsl_ioread64':
./include/linux/kernel.h:189:37: error: invalid operands to binary & (have 'const u64 *' {aka 'const long long unsigned int *'} and 'unsigned int')
  189 | #define lower_32_bits(n) ((u32)((n) & 0xffffffff))
      |                                     ^
drivers/dma/fsldma.h:208:17: note: in expansion of macro 'lower_32_bits'
  208 |  u32 fsl_addr = lower_32_bits(addr);
      |                 ^~~~~~~~~~~~~
drivers/dma/fsldma.h: In function 'fsl_ioread64be':
./include/linux/kernel.h:189:37: error: invalid operands to binary & (have 'const u64 *' {aka 'const long long unsigned int *'} and 'unsigned int')
  189 | #define lower_32_bits(n) ((u32)((n) & 0xffffffff))
      |                                     ^
drivers/dma/fsldma.h:222:17: note: in expansion of macro 'lower_32_bits'
  222 |  u32 fsl_addr = lower_32_bits(addr);
      |                 ^~~~~~~~~~~~~
make[2]: *** [drivers/dma/fsldma.o] Error 1

Bisct log attached.

Guenter

---
# bad: [4d41ead6ead97c3730bbd186a601a64828668f01] Merge tag 'block-5.9-2020-08-28' of git://git.kernel.dk/linux-block
# good: [15bc20c6af4ceee97a1f90b43c0e386643c071b4] Merge tag 'tty-5.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
git bisect start 'HEAD' '15bc20c6af4c'
# good: [5ec06b5c0d259a8c7c4376b121b2f62dfbfe57ef] Merge tag 'drm-fixes-2020-08-28' of git://anongit.freedesktop.org/drm/drm
git bisect good 5ec06b5c0d259a8c7c4376b121b2f62dfbfe57ef
# bad: [326e311b849426a95cac0149406efb2bbd13fa65] Merge tag 'pm-5.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
git bisect bad 326e311b849426a95cac0149406efb2bbd13fa65
# good: [e30942859030199dab5ad73f95faac226133c639] Merge tag 'writeback_for_v5.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
git bisect good e30942859030199dab5ad73f95faac226133c639
# bad: [96d454cd2c1668010406ea4c28ab915bcbb747f4] Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
git bisect bad 96d454cd2c1668010406ea4c28ab915bcbb747f4
# good: [e9ee186bb735bfc17fa81dbc9aebf268aee5b41e] KVM: arm64: Add kvm_extable for vaxorcism code
git bisect good e9ee186bb735bfc17fa81dbc9aebf268aee5b41e
# good: [71a7f8cb1ca4ca7214a700b1243626759b6c11d4] KVM: arm64: Set HCR_EL2.PTW to prevent AT taking synchronous exception
git bisect good 71a7f8cb1ca4ca7214a700b1243626759b6c11d4
# bad: [ef91bb196b0db1013ef8705367bc2d7944ef696b] kernel.h: Silence sparse warning in lower_32_bits
git bisect bad ef91bb196b0db1013ef8705367bc2d7944ef696b
# first bad commit: [ef91bb196b0db1013ef8705367bc2d7944ef696b] kernel.h: Silence sparse warning in lower_32_bits

Patch
diff mbox series

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 500def620d8f..c25b8e41c0ea 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -186,7 +186,7 @@ 
  * lower_32_bits - return bits 0-31 of a number
  * @n: the number we're accessing
  */
-#define lower_32_bits(n) ((u32)(n))
+#define lower_32_bits(n) ((u32)((n) & 0xffffffff))
 
 struct completion;
 struct pt_regs;