Leon Romanovsky e537deecda RDMA/mana_ib: Add flex array to struct mana_cfg_rx_steer_req_v2
The "struct mana_cfg_rx_steer_req_v2" uses a dynamically sized set of
trailing elements. Specifically, it uses a "mana_handle_t" array. So,
use the preferred way in the kernel declaring a flexible array [1].

At the same time, prepare for the coming implementation by GCC and Clang
of the __counted_by attribute. Flexible array members annotated with
__counted_by can have their accesses bounds-checked at run-time via
CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for
strcpy/memcpy-family functions).

Also, avoid the open-coded arithmetic in the memory allocator functions
[2] using the "struct_size" macro.

Moreover, use the "offsetof" helper to get the indirect table offset
instead of the "sizeof" operator and avoid the open-coded arithmetic in
pointers using the new flex member. This new structure member also allow
us to remove the "req_indir_tab" variable since it is no longer needed.

Now, it is also possible to use the "flex_array_size" helper to compute
the size of these trailing elements in the "memcpy" function.

Specifically, the first commit adds the flex member and the patches 2
and 3 refactor the consumers of the "struct mana_cfg_rx_steer_req_v2".

This code was detected with the help of Coccinelle, and audited and
modified manually. The Coccinelle script used to detect this code
pattern is the following:

virtual report

@rule1@
type t1;
type t2;
identifier i0;
identifier i1;
identifier i2;
identifier ALLOC =~
"kmalloc|kzalloc|kmalloc_node|kzalloc_node|vmalloc|vzalloc|kvmalloc|kvzalloc";
position p1;
@@

i0 = sizeof(t1) + sizeof(t2) * i1;
...
i2 = ALLOC@p1(..., i0, ...);

@script:python depends on report@
p1 << rule1.p1;
@@

msg = "WARNING: verify allocation on line %s" % (p1[0].line)
coccilib.report.print_report(p1[0],msg)

[1] https://www.kernel.org/doc/html/next/process/deprecated.html#zero-length-and-one-element-arrays
[2] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
Link: https://lore.kernel.org/all/AS8PR02MB72374BD1B23728F2E3C3B1A18B022@AS8PR02MB7237.eurprd02.prod.outlook.com
Signed-off-by: Erick Archer <erick.archer@outlook.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>

* mana-ib-flex:
  net: mana: Avoid open coded arithmetic
  RDMA/mana_ib: Prefer struct_size over open coded arithmetic
  net: mana: Add flex array to struct mana_cfg_rx_steer_req_v2
2024-04-11 13:48:53 +03:00
..
2024-03-13 18:34:05 -07:00
2024-03-29 19:00:09 +01:00
2024-03-21 13:34:15 -07:00
2024-03-22 12:46:07 -07:00
2024-03-07 21:52:03 +00:00
2024-03-19 11:57:26 -07:00
2024-03-15 11:58:32 -07:00
2024-03-07 20:37:04 +00:00
2024-03-15 12:25:13 -07:00
2024-03-31 11:23:51 -07:00
2024-03-14 09:56:15 -07:00
2024-03-21 10:01:02 -07:00
2024-03-06 14:03:31 +00:00
2024-03-07 20:32:47 +00:00
2024-03-07 20:26:24 -08:00
2024-03-15 17:53:48 -07:00
2024-03-29 09:48:07 -04:00
2024-03-18 17:30:46 +00:00
2024-03-13 10:59:28 -07:00
2024-03-21 12:44:10 -07:00
2024-03-23 08:43:21 -07:00
2024-03-07 20:32:38 +00:00
2024-03-15 11:58:32 -07:00
2024-03-21 13:23:07 -06:00
2024-03-21 13:34:15 -07:00
2024-03-14 10:58:27 -07:00
2024-03-21 12:35:20 -07:00
2024-03-31 11:23:51 -07:00
2024-03-13 11:33:10 -07:00
2024-03-12 17:44:08 -07:00
2024-03-25 07:31:26 +01:00
2024-03-22 09:52:37 -07:00
2024-03-21 10:37:39 -07:00
2024-03-21 17:16:46 -07:00
2024-03-25 19:46:49 -07:00
2024-03-21 15:18:18 -07:00
2024-03-15 12:22:52 -07:00
2024-03-22 09:57:00 -07:00
2024-03-12 10:35:24 -07:00
2024-03-21 12:44:10 -07:00
2024-03-15 13:21:13 -07:00
2024-03-19 08:57:39 -07:00
2024-03-17 12:06:10 -07:00
2024-03-19 08:48:09 -07:00