Re: bridge.c:157:11: error: variable 'err' is used uninitialized whenever 'if' condition is false

From: Linus Torvalds
Date: Mon Sep 06 2021 - 12:40:16 EST


On Mon, Sep 6, 2021 at 2:11 AM Naresh Kamboju <naresh.kamboju@xxxxxxxxxx> 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