Re: [PATCH] soc/tegra: fuse: Fix bitwise vs. logical OR warning

From: Nathan Chancellor
Date: Mon Oct 25 2021 - 10:34:35 EST


Hi Michał,

On Thu, Oct 21, 2021 at 11:55:34PM +0200, Michał Mirosław wrote:
> On Thu, Oct 21, 2021 at 02:45:00PM -0700, Nathan Chancellor wrote:
> [...]
> > --- a/drivers/soc/tegra/fuse/speedo-tegra20.c
> > +++ b/drivers/soc/tegra/fuse/speedo-tegra20.c
> > @@ -69,7 +69,7 @@ void __init tegra20_init_speedo_data(struct tegra_sku_info *sku_info)
> >
> > val = 0;
> > for (i = CPU_SPEEDO_MSBIT; i >= CPU_SPEEDO_LSBIT; i--) {
> > - reg = tegra_fuse_read_spare(i) |
> > + reg = tegra_fuse_read_spare(i) ||
> > tegra_fuse_read_spare(i + CPU_SPEEDO_REDUND_OFFS);
> > val = (val << 1) | (reg & 0x1);
> > }
> > @@ -84,7 +84,7 @@ void __init tegra20_init_speedo_data(struct tegra_sku_info *sku_info)
> >
> > val = 0;
> > for (i = SOC_SPEEDO_MSBIT; i >= SOC_SPEEDO_LSBIT; i--) {
> > - reg = tegra_fuse_read_spare(i) |
> > + reg = tegra_fuse_read_spare(i) ||
> > tegra_fuse_read_spare(i + SOC_SPEEDO_REDUND_OFFS);
> > val = (val << 1) | (reg & 0x1);
> > }
>
> It does seem correct, but nevertheless the code looks suspicious. reg is
> already masked with 0x1 as far as I can tell, and there are other places
> which depend on this (like speedo-tegra210.c). Guessing from the use of
> tegra_fuse_read_spare() I would recommend changing its return type as it
> is returing a bit value, not necessarily semantically a boolean.

Yes, I did notice that, as well as the use of tegra_fuse_read_spare()
with boolean operators in tegra-apbmisc.c. I could change it to int if
that is what the maintainers prefer, which would also solve the warning.

Cheers,
Nathan