linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false
@ 2021-09-06  9:10 Naresh Kamboju
  2021-09-06 16:39 ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Naresh Kamboju @ 2021-09-06  9:10 UTC (permalink / raw)
  To: open list, clang-built-linux, lkft-triage, Netdev
  Cc: Linus Torvalds, Nathan Chancellor, Nick Desaulniers, David S. Miller

[Please ignore if it is already reported]

Following build warnings/ errors noticed while building linux mainline
master branch
with clang-nightly, clang-13, clang-12, clang-11 and clang-10 for
arm64 architecture.
Whereas gcc-11 build pass.

# to reproduce this build locally: tuxmake --target-arch=arm64
--kconfig=defconfig --toolchain=clang-nightly --wrapper=none
--environment=KBUILD_BUILD_TIMESTAMP=@1630870764
--environment=KBUILD_BUILD_USER=tuxmake
--environment=KBUILD_BUILD_HOST=tuxmake --runtime=podman
--image=855116176053.dkr.ecr.us-east-1.amazonaws.com/tuxmake/arm64_clang-nightly
config default kernel xipkernel modules dtbs dtbs-legacy debugkernel
headers
make --silent --keep-going --jobs=8
O=/home/tuxbuild/.cache/tuxmake/builds/current ARCH=arm64
CROSS_COMPILE=aarch64-linux-gnu- HOSTCC=clang CC=clang defconfig
make --silent --keep-going --jobs=8
O=/home/tuxbuild/.cache/tuxmake/builds/current ARCH=arm64
CROSS_COMPILE=aarch64-linux-gnu- HOSTCC=clang CC=clang
scripts/dtc/include-prefixes/arm/bcm2711-rpi-4-b.dts:220.10-231.4:
Warning (pci_device_reg): /scb/pcie@7d500000/pci@1,0: PCI unit address
format error, expected 0,0
scripts/dtc/include-prefixes/arm/bcm2711-rpi-4-b.dts:220.10-231.4:
Warning (pci_device_reg): /scb/pcie@7d500000/pci@1,0: PCI unit address
format error, expected 0,0
arch/arm64/boot/dts/rockchip/rk3399-gru.dtsi:464.3-52: Warning
(pci_device_reg): /pcie@f8000000/pcie@0,0:reg: PCI reg address is not
configuration space
arch/arm64/boot/dts/rockchip/rk3399-gru.dtsi:464.3-52: Warning
(pci_device_reg): /pcie@f8000000/pcie@0,0:reg: PCI reg address is not
configuration space
arch/arm64/boot/dts/rockchip/rk3399-gru.dtsi:464.3-52: Warning
(pci_device_reg): /pcie@f8000000/pcie@0,0:reg: PCI reg address is not
configuration space
arch/arm64/boot/dts/rockchip/rk3399-gru.dtsi:464.3-52: Warning
(pci_device_reg): /pcie@f8000000/pcie@0,0:reg: PCI reg address is not
configuration space
arch/arm64/kvm/hyp/nvhe/Makefile:58: FORCE prerequisite is missing
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:157:11: error:
variable 'err' is used uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
        else if (mlx5_esw_bridge_dev_same_hw(rep, esw))
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:164:9: note:
uninitialized use occurs here
        return err;
               ^~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:157:7: note:
remove the 'if' if its condition is always true
        else if (mlx5_esw_bridge_dev_same_hw(rep, esw))
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:140:9: note:
initialize the variable 'err' to silence this warning
        int err;
               ^
                = 0
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:262:7: error:
variable 'err' is used uninitialized whenever switch case is taken
[-Werror,-Wsometimes-uninitialized]
        case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:276:9: note:
uninitialized use occurs here
        return err;
               ^~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:257:7: error:
variable 'err' is used uninitialized whenever 'if' condition is false
[-Werror,-Wsometimes-uninitialized]
                if (attr->u.brport_flags.mask & ~(BR_LEARNING |
BR_FLOOD | BR_MCAST_FLOOD)) {

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:276:9: note:
uninitialized use occurs here
        return err;
               ^~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:257:3: note:
remove the 'if' if its condition is always true
                if (attr->u.brport_flags.mask & ~(BR_LEARNING |
BR_FLOOD | BR_MCAST_FLOOD)) {

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:247:9: note:
initialize the variable 'err' to silence this warning
        int err;
               ^
                = 0
3 errors generated.
make[6]: *** [scripts/Makefile.build:277:
drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.o] Error 1
make[6]: Target '__build' not remade because of errors.
make[5]: *** [scripts/Makefile.build:540:
drivers/net/ethernet/mellanox/mlx5/core] Error 2
make[5]: Target '__build' not remade because of errors.
make[4]: *** [scripts/Makefile.build:540: drivers/net/ethernet/mellanox] Error 2
make[4]: Target '__build' not remade because of errors.
make[3]: *** [scripts/Makefile.build:540: drivers/net/ethernet] Error 2
make[3]: Target '__build' not remade because of errors.
make[2]: *** [scripts/Makefile.build:540: drivers/net] Error 2
make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1872: drivers] Error 2
make[1]: Target '__all' not remade because of errors.
make: *** [Makefile:219: __sub-make] Error 2
make: Target '__all' not remade because of errors.

Build config:
https://builds.tuxbuild.com/1xjZrnXEZfc3qYzziclNRaugAaN/config

Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>

meta data:
-----------
    git_describe: v5.14-9687-g27151f177827
    git_repo: https://gitlab.com/Linaro/lkft/mirrors/torvalds/linux-mainline
    git_sha: 27151f177827d478508e756c7657273261aaf8a9
    git_short_log: 27151f177827 (\Merge tag
'perf-tools-for-v5.15-2021-09-04' of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux\)
    kconfig: [
        defconfig
    ],
    kernel_version: 5.14.0
    status_message: failure while building tuxmake target(s): default
    target_arch: arm64
    toolchain: clang-nightly, clang-13, clang-12, clang-11 and clang-10

steps to reproduce:
https://builds.tuxbuild.com/1xjZrnXEZfc3qYzziclNRaugAaN/tuxmake_reproducer.sh

--
Linaro LKFT
https://lkft.linaro.org

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

* Re: bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false
  2021-09-06  9:10 bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false Naresh Kamboju
@ 2021-09-06 16:39 ` Linus Torvalds
  2021-09-06 17:35   ` Vlad Buslov
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2021-09-06 16:39 UTC (permalink / raw)
  To: Naresh Kamboju, Vlad Buslov
  Cc: open list, clang-built-linux, lkft-triage, Netdev,
	Nathan Chancellor, Nick Desaulniers, David S. Miller

On Mon, Sep 6, 2021 at 2:11 AM Naresh Kamboju <naresh.kamboju@linaro.org> wrote:
>
> drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:157:11: error:
> variable 'err' is used uninitialized whenever 'if' condition is false

That compiler warning (now error) seems to be entirely valid.

That's a

    if (..)
    else if (..)

and if neither are valid then the code will return an uninitialized 'err'.

It's possible the two conditionals are guaranteed to cover all cases,
but as the compiler says, in that case the "if" in the else clause is
pointless and should be removed.

But it does look like 'ret' should probably just be initialized to 0.

              Linus

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

* Re: bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false
  2021-09-06 16:39 ` Linus Torvalds
@ 2021-09-06 17:35   ` Vlad Buslov
  2021-09-07 20:34     ` Saeed Mahameed
  0 siblings, 1 reply; 4+ messages in thread
From: Vlad Buslov @ 2021-09-06 17:35 UTC (permalink / raw)
  To: Linus Torvalds, Saeed Mahameed
  Cc: Naresh Kamboju, open list, clang-built-linux, lkft-triage,
	Netdev, Nathan Chancellor, Nick Desaulniers, David S. Miller

On Mon 06 Sep 2021 at 19:39, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> On Mon, Sep 6, 2021 at 2:11 AM Naresh Kamboju <naresh.kamboju@linaro.org> wrote:
>>
>> drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:157:11: error:
>> variable 'err' is used uninitialized whenever 'if' condition is false
>
> That compiler warning (now error) seems to be entirely valid.

I agree, this is a real issue. It had been reported before and my fix
for it was submitted by Saeed last week but wasn't accepted since it was
part of larger series that also included features and net-next had
already been closed by that time. As far as I understand it is pending
submission to net as part of series of bug fixes. Sorry for the delay.

>
> That's a
>
>     if (..)
>     else if (..)
>
> and if neither are valid then the code will return an uninitialized 'err'.
>
> It's possible the two conditionals are guaranteed to cover all cases,
> but as the compiler says, in that case the "if" in the else clause is
> pointless and should be removed.
>
> But it does look like 'ret' should probably just be initialized to 0.

Yep, this if exactly what I did in my patch "net/mlx5: Bridge, fix
uninitialized variable usage".

>
>               Linus


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

* Re: bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false
  2021-09-06 17:35   ` Vlad Buslov
@ 2021-09-07 20:34     ` Saeed Mahameed
  0 siblings, 0 replies; 4+ messages in thread
From: Saeed Mahameed @ 2021-09-07 20:34 UTC (permalink / raw)
  To: torvalds, Vlad Buslov
  Cc: davem, lkft-triage, natechancellor, clang-built-linux,
	linux-kernel, netdev, ndesaulniers, naresh.kamboju

On Mon, 2021-09-06 at 20:35 +0300, Vlad Buslov wrote:
> On Mon 06 Sep 2021 at 19:39, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> > On Mon, Sep 6, 2021 at 2:11 AM Naresh Kamboju
> > <naresh.kamboju@linaro.org> wrote:
> > > 
> > > drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c:157:11:
> > > error:
> > > variable 'err' is used uninitialized whenever 'if' condition is
> > > false
> > 
> > That compiler warning (now error) seems to be entirely valid.
> 
> I agree, this is a real issue. It had been reported before and my fix
> for it was submitted by Saeed last week but wasn't accepted since it
> was
> part of larger series that also included features and net-next had
> already been closed by that time. As far as I understand it is
> pending
> submission to net as part of series of bug fixes. Sorry for the
> delay.
> 
> 

yes, the fix will be submitted shortly to net/rc branch.
due to bad net-next timing the patch couldn't make it to -next.


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

end of thread, other threads:[~2021-09-07 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  9:10 bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false Naresh Kamboju
2021-09-06 16:39 ` Linus Torvalds
2021-09-06 17:35   ` Vlad Buslov
2021-09-07 20:34     ` Saeed Mahameed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).