Skip to contentSkip to conversation

Net: netfilter: Moved vmalloc call to kmalloc call

PATCH In review Charlie Sale 3 participants 3 messages Nov 2, 2017 – Nov 3, 2017

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

PATCH 1/1 Net: netfilter: Moved vmalloc call to kmalloc call

Fixed FIXME comment in code my changing a vmalloc call to a kmalloc call. Thought it would be a good place to start for a first patch.

---
 net/netfilter/xt_hashlimit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/xt_hashlimit.c +3 -3
index 5da8746f7b88..4eab1befe03c 100644
@@ -286,9 +286,9 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg,
 		if (size < 16)
 			size = 16;
 	}
-	/* FIXME: don't use vmalloc() here or anywhere else -HW */
-	hinfo = vmalloc(sizeof(struct xt_hashlimit_htable) +
-	                sizeof(struct hlist_head) * size);
+
+	hinfo = kmalloc(sizeof(*hinfo) +
+			sizeof(struct hlist_head) * size, GPT_KERNEL);
 	if (hinfo == NULL)
 		return -ENOMEM;
 	*out_hinfo = hinfo;
Signature · 1 line
2.13.6
maintainer
#1 lore raw
Quoted 3 lines · Charlie Sale

Fixed FIXME comment in code my changing a vmalloc call to a kmalloc call. Thought it would be a good place to start for a first patch.

Please at least compile test your patches.

net/netfilter/xt_hashlimit.c static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, · line 291

Quoted 6 lines
net/netfilter/xt_hashlimit.c +3 -3
-	/* FIXME: don't use vmalloc() here or anywhere else -HW */
-	hinfo = vmalloc(sizeof(struct xt_hashlimit_htable) +
-	                sizeof(struct hlist_head) * size);
+
+	hinfo = kmalloc(sizeof(*hinfo) +
+			sizeof(struct hlist_head) * size, GPT_KERNEL);

If anything this should be switched to kvmalloc, not kmalloc.

Also, hinfo cannot be free'd via vfree after this change, so you need to adjust all free operations too.