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

Jason Gunthorpe
2017-10-29T17:37:03Z

On Sun, Oct 29, 2017 at 03:01:10PM +0200, Yishai Hadas wrote:

> diff --git a/providers/mlx5/buf.c b/providers/mlx5/buf.c
> index 8196db6..0ba8188 100644
> +++ 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));

bitmap->table is sensibly set to a 'unsigned long' but here, and in
several other related macros, 'long' is used instead.. Looks weird to
mix and match the sigend and unsigned versions.

Generally, I prefer:
bitmap->table = calloc(BITS_TO_LONGS(bitmap->max),
sizeof(*bitmap->table));

Jason