Skip to contentSkip to conversation

net/sched: cls_u32: Use struct_size() in kzalloc()

PATCH Applied Gustavo A. R. Silva 2 participants 2 messages Jun 18, 2020 – Jun 20, 2020

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

PATCH 1/1 net/sched: cls_u32: 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.

---
 net/sched/cls_u32.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/sched/cls_u32.c +1 -3
index e15ff335953d..771b068f8254 100644
@@ -796,9 +796,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,
 	struct tc_u32_sel *s = &n->sel;
 	struct tc_u_knode *new;
 
-	new = kzalloc(sizeof(*n) + s->nkeys*sizeof(struct tc_u32_key),
-		      GFP_KERNEL);
-
+	new = kzalloc(struct_size(new, sel.keys, s->nkeys), GFP_KERNEL);
 	if (!new)
 		return NULL;
 
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw

From: "Gustavo A. R. Silva" <[email protected]>
Date: Thu, 18 Jun 2020 09:53:42 -0500

Quoted 7 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.

Applied.