Skip to contentSkip to conversation

taprio: Use struct_size() in kzalloc()

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

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

PATCH 1/1 taprio: 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. Also, remove unnecessary variable _size_.

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

---
 net/sched/sch_taprio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/sched/sch_taprio.c +2 -3
index b1eb12d33b9a..e981992634dd 100644
@@ -1108,11 +1108,10 @@ static void setup_txtime(struct taprio_sched *q,
 
 static struct tc_taprio_qopt_offload *taprio_offload_alloc(int num_entries)
 {
-	size_t size = sizeof(struct tc_taprio_sched_entry) * num_entries +
-		      sizeof(struct __tc_taprio_qopt_offload);
 	struct __tc_taprio_qopt_offload *__offload;
 
-	__offload = kzalloc(size, GFP_KERNEL);
+	__offload = kzalloc(struct_size(__offload, offload.entries, num_entries),
+			    GFP_KERNEL);
 	if (!__offload)
 		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:46:48 -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. Also, remove unnecessary variable _size_.

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

Applied, thank you.