diff options
author | Pekka Enberg <penberg@cs.helsinki.fi> | 2008-03-10 19:43:41 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-03-10 19:43:41 -0400 |
commit | 019f692ea719a2da17606511d2648b8cc1762268 (patch) | |
tree | 361999750dade856ff7dd1a5cb2ec2a06370f922 /net | |
parent | 3d89e9cf3690b4645ce73b86c219c8188f8fa50a (diff) |
[NETFILTER]: nf_conntrack: replace horrible hack with ksize()
There's a horrible slab abuse in net/netfilter/nf_conntrack_extend.c
that can be replaced with a call to ksize().
Cc: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/netfilter/nf_conntrack_extend.c | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/net/netfilter/nf_conntrack_extend.c b/net/netfilter/nf_conntrack_extend.c index 8b9be1e978cd..2bd9963b5b3e 100644 --- a/net/netfilter/nf_conntrack_extend.c +++ b/net/netfilter/nf_conntrack_extend.c | |||
@@ -19,14 +19,6 @@ | |||
19 | static struct nf_ct_ext_type *nf_ct_ext_types[NF_CT_EXT_NUM]; | 19 | static struct nf_ct_ext_type *nf_ct_ext_types[NF_CT_EXT_NUM]; |
20 | static DEFINE_MUTEX(nf_ct_ext_type_mutex); | 20 | static DEFINE_MUTEX(nf_ct_ext_type_mutex); |
21 | 21 | ||
22 | /* Horrible trick to figure out smallest amount worth kmallocing. */ | ||
23 | #define CACHE(x) (x) + 0 * | ||
24 | enum { | ||
25 | NF_CT_EXT_MIN_SIZE = | ||
26 | #include <linux/kmalloc_sizes.h> | ||
27 | 1 }; | ||
28 | #undef CACHE | ||
29 | |||
30 | void __nf_ct_ext_destroy(struct nf_conn *ct) | 22 | void __nf_ct_ext_destroy(struct nf_conn *ct) |
31 | { | 23 | { |
32 | unsigned int i; | 24 | unsigned int i; |
@@ -53,7 +45,7 @@ EXPORT_SYMBOL(__nf_ct_ext_destroy); | |||
53 | static void * | 45 | static void * |
54 | nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) | 46 | nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) |
55 | { | 47 | { |
56 | unsigned int off, len, real_len; | 48 | unsigned int off, len; |
57 | struct nf_ct_ext_type *t; | 49 | struct nf_ct_ext_type *t; |
58 | 50 | ||
59 | rcu_read_lock(); | 51 | rcu_read_lock(); |
@@ -61,16 +53,14 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) | |||
61 | BUG_ON(t == NULL); | 53 | BUG_ON(t == NULL); |
62 | off = ALIGN(sizeof(struct nf_ct_ext), t->align); | 54 | off = ALIGN(sizeof(struct nf_ct_ext), t->align); |
63 | len = off + t->len; | 55 | len = off + t->len; |
64 | real_len = t->alloc_size; | ||
65 | rcu_read_unlock(); | 56 | rcu_read_unlock(); |
66 | 57 | ||
67 | *ext = kzalloc(real_len, gfp); | 58 | *ext = kzalloc(t->alloc_size, gfp); |
68 | if (!*ext) | 59 | if (!*ext) |
69 | return NULL; | 60 | return NULL; |
70 | 61 | ||
71 | (*ext)->offset[id] = off; | 62 | (*ext)->offset[id] = off; |
72 | (*ext)->len = len; | 63 | (*ext)->len = len; |
73 | (*ext)->real_len = real_len; | ||
74 | 64 | ||
75 | return (void *)(*ext) + off; | 65 | return (void *)(*ext) + off; |
76 | } | 66 | } |
@@ -95,7 +85,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) | |||
95 | newlen = newoff + t->len; | 85 | newlen = newoff + t->len; |
96 | rcu_read_unlock(); | 86 | rcu_read_unlock(); |
97 | 87 | ||
98 | if (newlen >= ct->ext->real_len) { | 88 | if (newlen >= ksize(ct->ext)) { |
99 | new = kmalloc(newlen, gfp); | 89 | new = kmalloc(newlen, gfp); |
100 | if (!new) | 90 | if (!new) |
101 | return NULL; | 91 | return NULL; |
@@ -114,7 +104,6 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp) | |||
114 | rcu_read_unlock(); | 104 | rcu_read_unlock(); |
115 | } | 105 | } |
116 | kfree(ct->ext); | 106 | kfree(ct->ext); |
117 | new->real_len = newlen; | ||
118 | ct->ext = new; | 107 | ct->ext = new; |
119 | } | 108 | } |
120 | 109 | ||
@@ -156,8 +145,6 @@ static void update_alloc_size(struct nf_ct_ext_type *type) | |||
156 | t1->alloc_size = ALIGN(t1->alloc_size, t2->align) | 145 | t1->alloc_size = ALIGN(t1->alloc_size, t2->align) |
157 | + t2->len; | 146 | + t2->len; |
158 | } | 147 | } |
159 | if (t1->alloc_size < NF_CT_EXT_MIN_SIZE) | ||
160 | t1->alloc_size = NF_CT_EXT_MIN_SIZE; | ||
161 | } | 148 | } |
162 | } | 149 | } |
163 | 150 | ||