Re: [PATCH] net: wwan: t7xx: Prefer struct_size over open coded arithmetic

From: Sergey Ryazanov
Date: Sat Feb 24 2024 - 16:39:33 EST


On 24.02.2024 20:19, Erick Archer wrote:
This is an effort to get rid of all multiplications from allocation
functions in order to prevent integer overflows [1][2].

As the "port_prox" variable is a pointer to "struct port_proxy" and
this structure ends in a flexible array:

struct port_proxy {
[...]
struct t7xx_port ports[];
};

the preferred way in the kernel is to use the struct_size() helper to
do the arithmetic instead of the argument "size + size * count" in the
devm_kzalloc() function.

This way, the code is more readable and safer.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: https://github.com/KSPP/linux/issues/160 [2]

Signed-off-by: Erick Archer <erick.archer@xxxxxxx>

Reviewed-by: Sergey Ryazanov <ryazanov.s.a@xxxxxxxxx>