If a user tries to allocate bitmap structure with invalid values, this may
cause a kernel panic.
Signed-off-by: Dotan Barak <dotanb@dev.mellanox.co.il>
Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
(Ported from Mellanox OFED 2.4)
Signed-off-by: Mukesh Kacker <mukesh.kacker@oracle.com>
int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
u32 reserved_bot, u32 reserved_top)
{
+ /* sanity check */
+ if (num <= (u64)reserved_top + reserved_bot)
+ return -EINVAL;
+
/* num must be a power of 2 */
if (num != roundup_pow_of_two(num))
return -EINVAL;