Skip to content

Commit 4af3ce0

Browse files
committed
IB/mlx4: Fix shutdown crash accessing a non-existent bitmap
Commit cfcde11 ("IB/mlx4: Use flow counters on IBoE ports") added code that sets elements of counters[] to -1 if no counter is allocated, but then goes ahead and passes every entry to mlx4_counter_free() on shutdown. This is a bad idea, especially if MLX4_DEV_CAP_FLAG_COUNTERS isn't set so there isn't even an underlying bitmap to free from. Tested-by: Sean Hefty <sean.hefty@intel.com> Cc: <stable@kernel.org> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent 5611cc4 commit 4af3ce0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • drivers/infiniband/hw/mlx4

‎drivers/infiniband/hw/mlx4/main.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,8 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
12441244

12451245
err_counter:
12461246
for (; i; --i)
1247-
mlx4_counter_free(ibdev->dev, ibdev->counters[i - 1]);
1247+
if (ibdev->counters[i - 1] != -1)
1248+
mlx4_counter_free(ibdev->dev, ibdev->counters[i - 1]);
12481249

12491250
err_map:
12501251
iounmap(ibdev->uar_map);
@@ -1275,7 +1276,8 @@ static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
12751276
}
12761277
iounmap(ibdev->uar_map);
12771278
for (p = 0; p < ibdev->num_ports; ++p)
1278-
mlx4_counter_free(ibdev->dev, ibdev->counters[p]);
1279+
if (ibdev->counters[p] != -1)
1280+
mlx4_counter_free(ibdev->dev, ibdev->counters[p]);
12791281
mlx4_foreach_port(p, dev, MLX4_PORT_TYPE_IB)
12801282
mlx4_CLOSE_PORT(dev, p);
12811283

0 commit comments

Comments
 (0)