Skip to content

Commit 8b69844

Browse files
rolanddgregkh
authored andcommitted
IB/mlx4: Fix shutdown crash accessing a non-existent bitmap
commit 4af3ce0 upstream. 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> Signed-off-by: Roland Dreier <roland@purestorage.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent 2c141bb commit 8b69844

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
@@ -1144,7 +1144,8 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
11441144

11451145
err_counter:
11461146
for (; i; --i)
1147-
mlx4_counter_free(ibdev->dev, ibdev->counters[i - 1]);
1147+
if (ibdev->counters[i - 1] != -1)
1148+
mlx4_counter_free(ibdev->dev, ibdev->counters[i - 1]);
11481149

11491150
err_map:
11501151
iounmap(ibdev->uar_map);
@@ -1175,7 +1176,8 @@ static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
11751176
}
11761177
iounmap(ibdev->uar_map);
11771178
for (p = 0; p < ibdev->num_ports; ++p)
1178-
mlx4_counter_free(ibdev->dev, ibdev->counters[p]);
1179+
if (ibdev->counters[p] != -1)
1180+
mlx4_counter_free(ibdev->dev, ibdev->counters[p]);
11791181
mlx4_foreach_port(p, dev, MLX4_PORT_TYPE_IB)
11801182
mlx4_CLOSE_PORT(dev, p);
11811183

0 commit comments

Comments
 (0)