Len Baker 7bb39a3944 net: hns: Prefer struct_size over open coded arithmetic
As noted in the "Deprecated Interfaces, Language Features, Attributes,
and Conventions" documentation [1], size calculations (especially
multiplication) should not be performed in memory allocator (or similar)
function arguments due to the risk of them overflowing. This could lead
to values wrapping around and a smaller allocation being made than the
caller was expecting. Using those allocations could lead to linear
overflows of heap memory and other misbehaviors.

So, take the opportunity to refactor the hnae_handle structure to switch
the last member to flexible array, changing the code accordingly. Also,
fix the comment in the hnae_vf_cb structure to inform that the ae_handle
member must be the last member.

Then, use the struct_size() helper to do the arithmetic instead of the
argument "size + count * size" in the kzalloc() function.

This code was detected with the help of Coccinelle and audited and fixed
manually.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Len Baker <len.baker@gmx.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-10-12 11:23:11 +01:00
..
2021-09-07 12:38:59 -07:00
2021-09-09 11:48:27 -07:00
2021-09-09 11:39:57 -07:00
2021-09-08 11:50:26 -07:00
2021-09-09 11:07:47 -07:00
2021-10-07 21:14:04 +02:00
2021-09-30 12:11:35 -07:00
2021-09-15 17:18:56 -07:00
2021-09-02 13:49:39 -07:00
2021-09-03 15:33:47 -07:00
2021-09-27 13:05:12 -07:00
2021-09-01 08:44:42 -07:00
2021-09-07 12:38:59 -07:00
2021-10-07 13:39:51 +01:00
2021-10-07 09:44:48 -07:00
2021-09-20 12:43:34 +01:00
2021-09-01 15:25:28 -07:00
2021-09-01 08:44:42 -07:00
2021-10-07 21:13:57 +02:00
2021-09-01 10:29:29 -07:00
2021-09-22 11:58:24 -07:00
2021-09-14 11:18:47 +02:00
2021-10-07 14:01:29 -07:00
2021-09-28 07:27:29 -07:00
2021-09-18 11:15:01 -07:00
2021-09-25 15:37:31 -07:00
2021-08-14 15:54:09 -06:00
2021-08-14 15:54:09 -06:00