Skip to contentSkip to conversation

x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)

PATCH New Loganaden Velvindron 1 participant 1 message Aug 10, 2016

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

PATCH 1/1 x_tables: Replace kmalloc(s*n) with kmalloc_array(n,s)

Replace kmalloc(s*n) with kmalloc_array(n,s), thus making it
easier to check that the calculation doesn't wrap or return a smaller allocation

---
 net/netfilter/x_tables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/x_tables.c +1 -1
index e0aa7c1..c8f20f2 100644
@@ -1513,7 +1513,7 @@ xt_hook_ops_alloc(const struct xt_table *table, nf_hookfn *fn)
 	if (!num_hooks)
 		return ERR_PTR(-EINVAL);
 
-	ops = kmalloc(sizeof(*ops) * num_hooks, GFP_KERNEL);
+	ops = kmalloc_array(num_hooks, sizeof(*ops), GFP_KERNEL);
 	if (ops == NULL)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.9.2