net: wwan: t7xx: Prefer struct_size over open coded arithmetic
authorErick Archer <erick.archer@gmx.com>
Sat, 24 Feb 2024 18:19:32 +0000 (19:19 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 28 Feb 2024 02:09:35 +0000 (18:09 -0800)
commit848e34ca203046c9b967034596828472f08e4ac7
tree5ac02a25408e28e10d5970d48ce3fd94f5f712b7
parentd75fe63a0708bd28eac5cda1212fa5fd037297dc
net: wwan: t7xx: Prefer struct_size over open coded arithmetic

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
Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Erick Archer <erick.archer@gmx.com>
Reviewed-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Link: https://lore.kernel.org/r/20240224181932.2720-1-erick.archer@gmx.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/wwan/t7xx/t7xx_port_proxy.c