diff mbox series

[next] net/mlx5: Bridge: Fix uninitialized variable err

Message ID 20210818142558.36722-1-colin.king@canonical.com (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [next] net/mlx5: Bridge: Fix uninitialized variable err | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 2 maintainers not CCed: jianbol@nvidia.com vladimir.oltean@nxp.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Colin King Aug. 18, 2021, 2:25 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

A recent change removed the assignment of err to the return from
the call mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get, so now
err is uninitialized. This is problematic in the switch statement
where attr-id is SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS, there
is now a possibility of err not being assigned and the function
returning a garbage value in err. Fix this by initializing err
to zero.

Addresses-Coverity; ("Uninitialized scalar variable")
Fixes: ff9b7521468b ("net/mlx5: Bridge, support LAG")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vlad Buslov Aug. 18, 2021, 3:16 p.m. UTC | #1
On Wed 18 Aug 2021 at 17:25, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> A recent change removed the assignment of err to the return from
> the call mlx5_esw_bridge_lower_rep_vport_num_vhca_id_get, so now
> err is uninitialized. This is problematic in the switch statement
> where attr-id is SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS, there
> is now a possibility of err not being assigned and the function
> returning a garbage value in err. Fix this by initializing err
> to zero.
>
> Addresses-Coverity; ("Uninitialized scalar variable")
> Fixes: ff9b7521468b ("net/mlx5: Bridge, support LAG")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---

Colin, thanks for fixing this!

Saeed, I've already submitted fix for this and another similar Coverity
issue (in mlx5_esw_bridge_port_changeupper()) internally. This patch is
exactly the same one line fix as mine, so you can take whichever you
prefer.

Reviewed-by: Vlad Buslov <vladbu@nvidia.com>

[...]
diff mbox series

Patch

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..4bf860f621f7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/bridge.c
@@ -244,7 +244,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))