* [PATCH net-next] net/mlx5: Fix use of uninitialized variable in bridge.c
@ 2021-09-14 12:12 Leon Romanovsky
2021-09-14 12:41 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Leon Romanovsky @ 2021-09-14 12:12 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Saeed Mahameed
Cc: Leon Romanovsky, linux-kernel, linux-rdma, Mark Bloch,
Naresh Kamboju, netdev, Roi Dayan, Vlad Buslov
From: Leon Romanovsky <leonro@nvidia.com>
Rewrite the code to fix the following compilation warnings that were
discovered once Linus enabled -Werror flag.
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.
Fixes: ff9b7521468b ("net/mlx5: Bridge, support LAG")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
.../mellanox/mlx5/core/en/rep/bridge.c | 36 +++++++++++--------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
index 0c38c2e319be..55b4ce37bcae 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
@@ -137,7 +137,6 @@ static int mlx5_esw_bridge_port_changeupper(struct notifier_block *nb, void *ptr
u16 vport_num, esw_owner_vhca_id;
struct netlink_ext_ack *extack;
int ifindex = upper->ifindex;
- int err;
if (!netif_is_bridge_master(upper))
return 0;
@@ -148,20 +147,29 @@ static int mlx5_esw_bridge_port_changeupper(struct notifier_block *nb, void *ptr
extack = netdev_notifier_info_to_extack(&info->info);
- if (mlx5_esw_bridge_is_local(dev, rep, esw))
- err = info->linking ?
- mlx5_esw_bridge_vport_link(ifindex, vport_num, esw_owner_vhca_id,
- br_offloads, extack) :
- mlx5_esw_bridge_vport_unlink(ifindex, vport_num, esw_owner_vhca_id,
- br_offloads, extack);
- else if (mlx5_esw_bridge_dev_same_hw(rep, esw))
- err = info->linking ?
- mlx5_esw_bridge_vport_peer_link(ifindex, vport_num, esw_owner_vhca_id,
- br_offloads, extack) :
- mlx5_esw_bridge_vport_peer_unlink(ifindex, vport_num, esw_owner_vhca_id,
+ if (mlx5_esw_bridge_is_local(dev, rep, esw)) {
+ if (info->linking)
+ return mlx5_esw_bridge_vport_link(ifindex, vport_num,
+ esw_owner_vhca_id,
br_offloads, extack);
- return err;
+ return mlx5_esw_bridge_vport_unlink(ifindex, vport_num,
+ esw_owner_vhca_id,
+ br_offloads, extack);
+ }
+
+ if (mlx5_esw_bridge_dev_same_hw(rep, esw)) {
+ if (info->linking)
+ return mlx5_esw_bridge_vport_peer_link(
+ ifindex, vport_num, esw_owner_vhca_id,
+ br_offloads, extack);
+ return mlx5_esw_bridge_vport_peer_unlink(ifindex, vport_num,
+ esw_owner_vhca_id,
+ br_offloads, extack);
+ }
+
+ WARN_ON(true);
+ return -EINVAL;
}
static int mlx5_esw_bridge_switchdev_port_event(struct notifier_block *nb,
@@ -244,7 +252,7 @@ mlx5_esw_bridge_port_obj_attr_set(struct net_device *dev,
struct netlink_ext_ack *extack = switchdev_notifier_info_to_extack(&port_attr_info->info);
const struct switchdev_attr *attr = port_attr_info->attr;
u16 vport_num, esw_owner_vhca_id;
- int err;
+ int err = 0;
if (!mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get(dev, br_offloads->esw, &vport_num,
&esw_owner_vhca_id))
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] net/mlx5: Fix use of uninitialized variable in bridge.c
2021-09-14 12:12 [PATCH net-next] net/mlx5: Fix use of uninitialized variable in bridge.c Leon Romanovsky
@ 2021-09-14 12:41 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2021-09-14 12:41 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Saeed Mahameed
Cc: linux-kernel, linux-rdma, Mark Bloch, Naresh Kamboju, netdev,
Roi Dayan, Vlad Buslov
On Tue, Sep 14, 2021 at 03:12:47PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
>
> Rewrite the code to fix the following compilation warnings that were
> discovered once Linus enabled -Werror flag.
>
> 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.
>
> Fixes: ff9b7521468b ("net/mlx5: Bridge, support LAG")
> Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> ---
> .../mellanox/mlx5/core/en/rep/bridge.c | 36 +++++++++++--------
> 1 file changed, 22 insertions(+), 14 deletions(-)
Vlad pointed to me that similar patch was already accepted.
https://patchwork.kernel.org/project/netdevbpf/patch/20210907212420.28529-2-saeed@kernel.org/
Can we please expedite the fix to Linus so our other branches (RDMA e.t.c)
that are based on pure -rcX from Linus will be compilation error free?
Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-14 12:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14 12:12 [PATCH net-next] net/mlx5: Fix use of uninitialized variable in bridge.c Leon Romanovsky
2021-09-14 12:41 ` Leon Romanovsky
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).