]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
net: stmmac: selftests: Use struct_size() helper in kzalloc()
authorGustavo A. R. Silva <gustavoars@kernel.org>
Tue, 16 Jun 2020 23:03:28 +0000 (18:03 -0500)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Jun 2020 03:19:20 +0000 (20:19 -0700)
Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

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

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c

index e6696495f1262fcdf126fb4c9c2a31f7f20d0b50..e113b1376fddac7056c804143f6e2390e5f3343b 100644 (file)
@@ -1094,7 +1094,7 @@ static int stmmac_test_rxp(struct stmmac_priv *priv)
        if (!priv->dma_cap.frpsel)
                return -EOPNOTSUPP;
 
-       sel = kzalloc(sizeof(*sel) + nk * sizeof(struct tc_u32_key), GFP_KERNEL);
+       sel = kzalloc(struct_size(sel, keys, nk), GFP_KERNEL);
        if (!sel)
                return -ENOMEM;