[PATCH rdma-core 2/2] mlx5: Fix wrong bitmap table allocation size calculation

Yishai Hadas
2017-10-29T13:01:10Z

From: Ariel Levkovich <lariel-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>

This fixes wrong element size calculation during allocation
of bitmap table. We divide the number of required bits in the bitmap
into groups (elements) of sizeof(long) which can be 4 or more bytes
(architecture depended) but allocating num_elements * 4 bytes of
memory for the table.

Signed-off-by: Ariel Levkovich <lariel-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Reviewed-by: Yishai Hadas <yishaih-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
providers/mlx5/buf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/providers/mlx5/buf.c b/providers/mlx5/buf.c
index 8196db6..0ba8188 100644
--- a/providers/mlx5/buf.c
+++ b/providers/mlx5/buf.c
@@ -51,7 +51,7 @@ static int mlx5_bitmap_init(struct mlx5_bitmap *bitmap, uint32_t num,
bitmap->avail = num;
bitmap->mask = mask;
bitmap->avail = bitmap->max;
- bitmap->table = calloc(BITS_TO_LONGS(bitmap->max), sizeof(uint32_t));
+ bitmap->table = calloc(BITS_TO_LONGS(bitmap->max), sizeof(long));
if (!bitmap->table)
return -ENOMEM;

--
1.8.3.1