From: Amit Cohen <amcohen@xxxxxxxxxx> Currently, there is a check in core code to validate that the received local port does not exceed number of ports in the switch. Next patch will have to validate it also in PCI, before accessing the pci_ports array. There is no reason to check it twice, so move this check to PCI code. Note that 'mlxsw_pci->max_ports' and 'mlxsw_core->max_ports' store the same value, which is read from firmware. Signed-off-by: Amit Cohen <amcohen@xxxxxxxxxx> Reviewed-by: Ido Schimmel <idosch@xxxxxxxxxx> Signed-off-by: Petr Machata <petrm@xxxxxxxxxx> --- drivers/net/ethernet/mellanox/mlxsw/core.c | 3 +-- drivers/net/ethernet/mellanox/mlxsw/pci.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index 628530e01b19..962283bbfe18 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2959,8 +2959,7 @@ void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb, const struct mlxsw_rx_listener *rxl; bool found = false; - if ((rx_info->trap_id >= MLXSW_TRAP_ID_MAX) || - (rx_info->local_port >= mlxsw_core->max_ports)) + if (rx_info->trap_id >= MLXSW_TRAP_ID_MAX) goto drop; rcu_read_lock(); diff --git a/drivers/net/ethernet/mellanox/mlxsw/pci.c b/drivers/net/ethernet/mellanox/mlxsw/pci.c index b560c21fd3ef..778493b21318 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/pci.c +++ b/drivers/net/ethernet/mellanox/mlxsw/pci.c @@ -845,6 +845,9 @@ static void mlxsw_pci_cqe_rdq_handle(struct mlxsw_pci *mlxsw_pci, rx_info.local_port = mlxsw_pci_cqe_system_port_get(cqe); } + if (rx_info.local_port >= mlxsw_pci->max_ports) + goto out; + err = mlxsw_pci_rx_pkt_info_init(q->pci, elem_info, byte_count, &rx_pkt_info); if (err) -- 2.47.0