linux/include/linux/mlx4
Kees Cook 4a6f18f286 net/mlx4_core: Avoid impossible mlx4_db_alloc() order value
GCC can see that the value range for "order" is capped, but this leads
it to consider that it might be negative, leading to a false positive
warning (with GCC 15 with -Warray-bounds -fdiagnostics-details):

../drivers/net/ethernet/mellanox/mlx4/alloc.c:691:47: error: array subscript -1 is below array bounds of 'long unsigned int *[2]' [-Werror=array-bounds=]
  691 |                 i = find_first_bit(pgdir->bits[o], MLX4_DB_PER_PAGE >> o);
      |                                    ~~~~~~~~~~~^~~
  'mlx4_alloc_db_from_pgdir': events 1-2
  691 |                 i = find_first_bit(pgdir->bits[o], MLX4_DB_PER_PAGE >> o);                        |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                     |                         |                                                   |                     |                         (2) out of array bounds here
      |                     (1) when the condition is evaluated to true                             In file included from ../drivers/net/ethernet/mellanox/mlx4/mlx4.h:53,
                 from ../drivers/net/ethernet/mellanox/mlx4/alloc.c:42:
../include/linux/mlx4/device.h:664:33: note: while referencing 'bits'
  664 |         unsigned long          *bits[2];
      |                                 ^~~~

Switch the argument to unsigned int, which removes the compiler needing
to consider negative values.

Signed-off-by: Kees Cook <kees@kernel.org>
Link: https://patch.msgid.link/20250210174504.work.075-kees@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
History 2025-02-14 19:47:35 -08:00
..
cmd.h net/mlx4: Spoofcheck and zero MAC can't coexist 2017-02-23 10:57:56 -05:00
cq.h RDMA/mlx4: Redo TX checksum offload in line with docs 2020-01-03 16:37:58 -04:00
device.h net/mlx4_core: Avoid impossible mlx4_db_alloc() order value 2025-02-14 19:47:35 -08:00
doorbell.h mlx4_core: Kill mlx4_write64_raw() 2007-10-14 20:17:39 -07:00
driver.h mlx4: Delete custom device management logic 2023-08-23 08:25:28 +01:00
qp.h v6.3 RDMA pull request 2023-02-24 15:11:03 -08:00
srq.h mlx4_core: Implement SRQ object lookup from srqn 2013-04-16 22:42:55 -07:00