Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc/tegra: fuse: Fix bitwise vs. logical OR warning

A new warning in clang points out two instances where boolean
expressions are being used with a bitwise OR instead of logical OR:

drivers/soc/tegra/fuse/speedo-tegra20.c:72:9: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
reg = tegra_fuse_read_spare(i) |
^~~~~~~~~~~~~~~~~~~~~~~~~~
||
drivers/soc/tegra/fuse/speedo-tegra20.c:72:9: note: cast one or both operands to int to silence this warning
drivers/soc/tegra/fuse/speedo-tegra20.c:87:9: warning: use of bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]
reg = tegra_fuse_read_spare(i) |
^~~~~~~~~~~~~~~~~~~~~~~~~~
||
drivers/soc/tegra/fuse/speedo-tegra20.c:87:9: note: cast one or both operands to int to silence this warning
2 warnings generated.

The motivation for the warning is that logical operations short circuit
while bitwise operations do not.

In this instance, tegra_fuse_read_spare() is not semantically returning
a boolean, it is returning a bit value. Use u32 for its return type so
that it can be used with either bitwise or boolean operators without any
warnings.

Fixes: 25cd5a391478 ("ARM: tegra: Add speedo-based process identification")
Link: https://github.com/ClangBuiltLinux/linux/issues/1488
Suggested-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>

authored by

Nathan Chancellor and committed by
Thierry Reding
a7083763 76d89474

+2 -2
+1 -1
drivers/soc/tegra/fuse/fuse-tegra.c
··· 320 320 }; 321 321 builtin_platform_driver(tegra_fuse_driver); 322 322 323 - bool __init tegra_fuse_read_spare(unsigned int spare) 323 + u32 __init tegra_fuse_read_spare(unsigned int spare) 324 324 { 325 325 unsigned int offset = fuse->soc->info->spare + spare * 4; 326 326
+1 -1
drivers/soc/tegra/fuse/fuse.h
··· 65 65 void tegra_init_revision(void); 66 66 void tegra_init_apbmisc(void); 67 67 68 - bool __init tegra_fuse_read_spare(unsigned int spare); 68 + u32 __init tegra_fuse_read_spare(unsigned int spare); 69 69 u32 __init tegra_fuse_read_early(unsigned int offset); 70 70 71 71 u8 tegra_get_major_rev(void);