diff options
author | Jack Morgenstein <jackm@dev.mellanox.co.il> | 2012-05-30 05:14:54 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-05-31 18:18:16 -0400 |
commit | 6230bb234dd17b4c92518e848368ce03f9802323 (patch) | |
tree | 4cad586a9fbed1568a687fe5aa67124f11b3cf98 /drivers/net | |
parent | b91cb3ebcd5ef8db956b8caa486d780dc52b07f1 (diff) |
net/mlx4_core: Check port out-of-range before using in mlx4_slave_cap
The range check was performed after using the port number.
Reverse this to prevent a potential array overflow.
Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/ethernet/mellanox/mlx4/main.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c index 7f71be0ca5f2..ee6f4fe00837 100644 --- a/drivers/net/ethernet/mellanox/mlx4/main.c +++ b/drivers/net/ethernet/mellanox/mlx4/main.c | |||
@@ -485,15 +485,15 @@ static int mlx4_slave_cap(struct mlx4_dev *dev) | |||
485 | dev->caps.num_mgms = 0; | 485 | dev->caps.num_mgms = 0; |
486 | dev->caps.num_amgms = 0; | 486 | dev->caps.num_amgms = 0; |
487 | 487 | ||
488 | for (i = 1; i <= dev->caps.num_ports; ++i) | ||
489 | dev->caps.port_mask[i] = dev->caps.port_type[i]; | ||
490 | |||
491 | if (dev->caps.num_ports > MLX4_MAX_PORTS) { | 488 | if (dev->caps.num_ports > MLX4_MAX_PORTS) { |
492 | mlx4_err(dev, "HCA has %d ports, but we only support %d, " | 489 | mlx4_err(dev, "HCA has %d ports, but we only support %d, " |
493 | "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS); | 490 | "aborting.\n", dev->caps.num_ports, MLX4_MAX_PORTS); |
494 | return -ENODEV; | 491 | return -ENODEV; |
495 | } | 492 | } |
496 | 493 | ||
494 | for (i = 1; i <= dev->caps.num_ports; ++i) | ||
495 | dev->caps.port_mask[i] = dev->caps.port_type[i]; | ||
496 | |||
497 | if (dev->caps.uar_page_size * (dev->caps.num_uars - | 497 | if (dev->caps.uar_page_size * (dev->caps.num_uars - |
498 | dev->caps.reserved_uars) > | 498 | dev->caps.reserved_uars) > |
499 | pci_resource_len(dev->pdev, 2)) { | 499 | pci_resource_len(dev->pdev, 2)) { |