net: ethernet: mlx4: Fix memory allocation in mlx4_buddy_init()
commitce391ac20e6308fab5819560aba6e01cccdd354e
authorShung-Hsi Yu <shung-hsi.yu@suse.com>
Mon, 31 Aug 2020 14:37:09 +0000 (31 22:37 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 12 Sep 2020 09:47:39 +0000 (12 11:47 +0200)
treee3ceb1d768933bf94b8d1d53341c9bf4f797410d
parente942ed86e5252fe206ef0c83f14bce331aa43d70
net: ethernet: mlx4: Fix memory allocation in mlx4_buddy_init()

commit cbedcb044e9cc4e14bbe6658111224bb923094f4 upstream.

On machines with much memory (> 2 TByte) and log_mtts_per_seg == 0, a
max_order of 31 will be passed to mlx_buddy_init(), which results in
s = BITS_TO_LONGS(1 << 31) becoming a negative value, leading to
kvmalloc_array() failure when it is converted to size_t.

  mlx4_core 0000:b1:00.0: Failed to initialize memory region table, aborting
  mlx4_core: probe of 0000:b1:00.0 failed with error -12

Fix this issue by changing the left shifting operand from a signed literal to
an unsigned one.

Fixes: 225c7b1feef1 ("IB/mlx4: Add a driver Mellanox ConnectX InfiniBand adapters")
Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/mellanox/mlx4/mr.c