Skip to contentSkip to conversation

net: stmmac: selftests: Use struct_size() in kzalloc()

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Jun 19, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: selftests: Use struct_size() in kzalloc()

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.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -1
index e6696495f126..e113b1376fdd 100644
@@ -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;
 
Signature · 1 line
2.27.0
maintainer
#1 lore raw

From: "Gustavo A. R. Silva" <[email protected]>
Date: Fri, 19 Jun 2020 12:41:54 -0500

Quoted 8 lines

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.

Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83

This doesn't apply to net-next.