All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] soc/tegra: fuse: Fix bitwise vs. logical OR warning
@ 2021-12-10 16:55 Nathan Chancellor
  2021-12-10 19:03 ` Nick Desaulniers
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2021-12-10 16:55 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter
  Cc: Nick Desaulniers, linux-tegra, linux-kernel, llvm,
	Nathan Chancellor, Michał Mirosław

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>
---

v1 -> v2: https://lore.kernel.org/r/20211021214500.2388146-1-nathan@kernel.org/

* Change return type of tegra_fuse_read_spare(), instead of changing
  bitwise OR to logical OR in tegra20_init_speedo_data() (Michał).

It would be nice to get this fixed sooner rather than later, as ARCH=arm
allmodconfig is broken due to -Werror.

 drivers/soc/tegra/fuse/fuse-tegra.c | 2 +-
 drivers/soc/tegra/fuse/fuse.h       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
index f2151815db58..e714ed3b61bc 100644
--- a/drivers/soc/tegra/fuse/fuse-tegra.c
+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
@@ -320,7 +320,7 @@ static struct platform_driver tegra_fuse_driver = {
 };
 builtin_platform_driver(tegra_fuse_driver);
 
-bool __init tegra_fuse_read_spare(unsigned int spare)
+u32 __init tegra_fuse_read_spare(unsigned int spare)
 {
 	unsigned int offset = fuse->soc->info->spare + spare * 4;
 
diff --git a/drivers/soc/tegra/fuse/fuse.h b/drivers/soc/tegra/fuse/fuse.h
index de58feba0435..ecff0c08e959 100644
--- a/drivers/soc/tegra/fuse/fuse.h
+++ b/drivers/soc/tegra/fuse/fuse.h
@@ -65,7 +65,7 @@ struct tegra_fuse {
 void tegra_init_revision(void);
 void tegra_init_apbmisc(void);
 
-bool __init tegra_fuse_read_spare(unsigned int spare);
+u32 __init tegra_fuse_read_spare(unsigned int spare);
 u32 __init tegra_fuse_read_early(unsigned int offset);
 
 u8 tegra_get_major_rev(void);

base-commit: 0fcfb00b28c0b7884635dacf38e46d60bf3d4eb1
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] soc/tegra: fuse: Fix bitwise vs. logical OR warning
  2021-12-10 16:55 [PATCH v2] soc/tegra: fuse: Fix bitwise vs. logical OR warning Nathan Chancellor
@ 2021-12-10 19:03 ` Nick Desaulniers
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Desaulniers @ 2021-12-10 19:03 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel, llvm,
	Michał Mirosław

On Fri, Dec 10, 2021 at 8:57 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> 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>

Thanks for the revised patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
> v1 -> v2: https://lore.kernel.org/r/20211021214500.2388146-1-nathan@kernel.org/
>
> * Change return type of tegra_fuse_read_spare(), instead of changing
>   bitwise OR to logical OR in tegra20_init_speedo_data() (Michał).
>
> It would be nice to get this fixed sooner rather than later, as ARCH=arm
> allmodconfig is broken due to -Werror.

Yes please let's try to get this into 5.16-rc5 if possible!

>
>  drivers/soc/tegra/fuse/fuse-tegra.c | 2 +-
>  drivers/soc/tegra/fuse/fuse.h       | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
> index f2151815db58..e714ed3b61bc 100644
> --- a/drivers/soc/tegra/fuse/fuse-tegra.c
> +++ b/drivers/soc/tegra/fuse/fuse-tegra.c
> @@ -320,7 +320,7 @@ static struct platform_driver tegra_fuse_driver = {
>  };
>  builtin_platform_driver(tegra_fuse_driver);
>
> -bool __init tegra_fuse_read_spare(unsigned int spare)
> +u32 __init tegra_fuse_read_spare(unsigned int spare)
>  {
>         unsigned int offset = fuse->soc->info->spare + spare * 4;
>
> diff --git a/drivers/soc/tegra/fuse/fuse.h b/drivers/soc/tegra/fuse/fuse.h
> index de58feba0435..ecff0c08e959 100644
> --- a/drivers/soc/tegra/fuse/fuse.h
> +++ b/drivers/soc/tegra/fuse/fuse.h
> @@ -65,7 +65,7 @@ struct tegra_fuse {
>  void tegra_init_revision(void);
>  void tegra_init_apbmisc(void);
>
> -bool __init tegra_fuse_read_spare(unsigned int spare);
> +u32 __init tegra_fuse_read_spare(unsigned int spare);
>  u32 __init tegra_fuse_read_early(unsigned int offset);
>
>  u8 tegra_get_major_rev(void);
>
> base-commit: 0fcfb00b28c0b7884635dacf38e46d60bf3d4eb1
> --
> 2.34.1
>
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-10 19:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 16:55 [PATCH v2] soc/tegra: fuse: Fix bitwise vs. logical OR warning Nathan Chancellor
2021-12-10 19:03 ` Nick Desaulniers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.