Commit 848e34ca authored by Erick Archer's avatar Erick Archer Committed by Jakub Kicinski

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 [1]
Link: https://github.com/KSPP/linux/issues/160 [2]
Signed-off-by: default avatarErick Archer <erick.archer@gmx.com>
Reviewed-by: default avatarSergey Ryazanov <ryazanov.s.a@gmail.com>
Link: https://lore.kernel.org/r/20240224181932.2720-1-erick.archer@gmx.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d75fe63a
...@@ -543,8 +543,10 @@ static int t7xx_proxy_alloc(struct t7xx_modem *md) ...@@ -543,8 +543,10 @@ static int t7xx_proxy_alloc(struct t7xx_modem *md)
struct device *dev = &md->t7xx_dev->pdev->dev; struct device *dev = &md->t7xx_dev->pdev->dev;
struct port_proxy *port_prox; struct port_proxy *port_prox;
port_prox = devm_kzalloc(dev, sizeof(*port_prox) + port_prox = devm_kzalloc(dev,
sizeof(struct t7xx_port) * T7XX_MAX_POSSIBLE_PORTS_NUM, struct_size(port_prox,
ports,
T7XX_MAX_POSSIBLE_PORTS_NUM),
GFP_KERNEL); GFP_KERNEL);
if (!port_prox) if (!port_prox)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment