Commit 32ea2776 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Saeed Mahameed

net/mlx5: Use the bitmap API to allocate bitmaps

Use bitmap_zalloc()/bitmap_free() instead of hand-writing them.

It is less verbose and it improves the semantic.
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 6a605eb1
...@@ -38,8 +38,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev) ...@@ -38,8 +38,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)); MLX5_LOG_SW_ICM_BLOCK_SIZE(dev));
dm->steering_sw_icm_alloc_blocks = dm->steering_sw_icm_alloc_blocks =
kcalloc(BITS_TO_LONGS(steering_icm_blocks), bitmap_zalloc(steering_icm_blocks, GFP_KERNEL);
sizeof(unsigned long), GFP_KERNEL);
if (!dm->steering_sw_icm_alloc_blocks) if (!dm->steering_sw_icm_alloc_blocks)
goto err_steering; goto err_steering;
} }
...@@ -50,8 +49,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev) ...@@ -50,8 +49,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)); MLX5_LOG_SW_ICM_BLOCK_SIZE(dev));
dm->header_modify_sw_icm_alloc_blocks = dm->header_modify_sw_icm_alloc_blocks =
kcalloc(BITS_TO_LONGS(header_modify_icm_blocks), bitmap_zalloc(header_modify_icm_blocks, GFP_KERNEL);
sizeof(unsigned long), GFP_KERNEL);
if (!dm->header_modify_sw_icm_alloc_blocks) if (!dm->header_modify_sw_icm_alloc_blocks)
goto err_modify_hdr; goto err_modify_hdr;
} }
...@@ -66,8 +64,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev) ...@@ -66,8 +64,7 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)); MLX5_LOG_SW_ICM_BLOCK_SIZE(dev));
dm->header_modify_pattern_sw_icm_alloc_blocks = dm->header_modify_pattern_sw_icm_alloc_blocks =
kcalloc(BITS_TO_LONGS(header_modify_pattern_icm_blocks), bitmap_zalloc(header_modify_pattern_icm_blocks, GFP_KERNEL);
sizeof(unsigned long), GFP_KERNEL);
if (!dm->header_modify_pattern_sw_icm_alloc_blocks) if (!dm->header_modify_pattern_sw_icm_alloc_blocks)
goto err_pattern; goto err_pattern;
} }
...@@ -75,10 +72,10 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev) ...@@ -75,10 +72,10 @@ struct mlx5_dm *mlx5_dm_create(struct mlx5_core_dev *dev)
return dm; return dm;
err_pattern: err_pattern:
kfree(dm->header_modify_sw_icm_alloc_blocks); bitmap_free(dm->header_modify_sw_icm_alloc_blocks);
err_modify_hdr: err_modify_hdr:
kfree(dm->steering_sw_icm_alloc_blocks); bitmap_free(dm->steering_sw_icm_alloc_blocks);
err_steering: err_steering:
kfree(dm); kfree(dm);
...@@ -97,7 +94,7 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev) ...@@ -97,7 +94,7 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev)
WARN_ON(!bitmap_empty(dm->steering_sw_icm_alloc_blocks, WARN_ON(!bitmap_empty(dm->steering_sw_icm_alloc_blocks,
BIT(MLX5_CAP_DEV_MEM(dev, log_steering_sw_icm_size) - BIT(MLX5_CAP_DEV_MEM(dev, log_steering_sw_icm_size) -
MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)))); MLX5_LOG_SW_ICM_BLOCK_SIZE(dev))));
kfree(dm->steering_sw_icm_alloc_blocks); bitmap_free(dm->steering_sw_icm_alloc_blocks);
} }
if (dm->header_modify_sw_icm_alloc_blocks) { if (dm->header_modify_sw_icm_alloc_blocks) {
...@@ -105,7 +102,7 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev) ...@@ -105,7 +102,7 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev)
BIT(MLX5_CAP_DEV_MEM(dev, BIT(MLX5_CAP_DEV_MEM(dev,
log_header_modify_sw_icm_size) - log_header_modify_sw_icm_size) -
MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)))); MLX5_LOG_SW_ICM_BLOCK_SIZE(dev))));
kfree(dm->header_modify_sw_icm_alloc_blocks); bitmap_free(dm->header_modify_sw_icm_alloc_blocks);
} }
if (dm->header_modify_pattern_sw_icm_alloc_blocks) { if (dm->header_modify_pattern_sw_icm_alloc_blocks) {
...@@ -113,7 +110,7 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev) ...@@ -113,7 +110,7 @@ void mlx5_dm_cleanup(struct mlx5_core_dev *dev)
BIT(MLX5_CAP_DEV_MEM(dev, BIT(MLX5_CAP_DEV_MEM(dev,
log_header_modify_pattern_sw_icm_size) - log_header_modify_pattern_sw_icm_size) -
MLX5_LOG_SW_ICM_BLOCK_SIZE(dev)))); MLX5_LOG_SW_ICM_BLOCK_SIZE(dev))));
kfree(dm->header_modify_pattern_sw_icm_alloc_blocks); bitmap_free(dm->header_modify_pattern_sw_icm_alloc_blocks);
} }
kfree(dm); kfree(dm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment