[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>

authored by Pekka Enberg and committed by David S. Miller 019f692e 3d89e9cf

+3 -17
-1
include/net/netfilter/nf_conntrack_extend.h
··· 17 struct nf_ct_ext { 18 u8 offset[NF_CT_EXT_NUM]; 19 u8 len; 20 - u8 real_len; 21 char data[0]; 22 }; 23
··· 17 struct nf_ct_ext { 18 u8 offset[NF_CT_EXT_NUM]; 19 u8 len; 20 char data[0]; 21 }; 22
+3 -16
net/netfilter/nf_conntrack_extend.c
··· 19 static struct nf_ct_ext_type *nf_ct_ext_types[NF_CT_EXT_NUM]; 20 static DEFINE_MUTEX(nf_ct_ext_type_mutex); 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) 31 { 32 unsigned int i; ··· 45 static void * 46 nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) 47 { 48 - unsigned int off, len, real_len; 49 struct nf_ct_ext_type *t; 50 51 rcu_read_lock(); ··· 53 BUG_ON(t == NULL); 54 off = ALIGN(sizeof(struct nf_ct_ext), t->align); 55 len = off + t->len; 56 - real_len = t->alloc_size; 57 rcu_read_unlock(); 58 59 - *ext = kzalloc(real_len, gfp); 60 if (!*ext) 61 return NULL; 62 63 (*ext)->offset[id] = off; 64 (*ext)->len = len; 65 - (*ext)->real_len = real_len; 66 67 return (void *)(*ext) + off; 68 } ··· 85 newlen = newoff + t->len; 86 rcu_read_unlock(); 87 88 - if (newlen >= ct->ext->real_len) { 89 new = kmalloc(newlen, gfp); 90 if (!new) 91 return NULL; ··· 104 rcu_read_unlock(); 105 } 106 kfree(ct->ext); 107 - new->real_len = newlen; 108 ct->ext = new; 109 } 110 ··· 145 t1->alloc_size = ALIGN(t1->alloc_size, t2->align) 146 + t2->len; 147 } 148 - if (t1->alloc_size < NF_CT_EXT_MIN_SIZE) 149 - t1->alloc_size = NF_CT_EXT_MIN_SIZE; 150 } 151 } 152
··· 19 static struct nf_ct_ext_type *nf_ct_ext_types[NF_CT_EXT_NUM]; 20 static DEFINE_MUTEX(nf_ct_ext_type_mutex); 21 22 void __nf_ct_ext_destroy(struct nf_conn *ct) 23 { 24 unsigned int i; ··· 53 static void * 54 nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp) 55 { 56 + unsigned int off, len; 57 struct nf_ct_ext_type *t; 58 59 rcu_read_lock(); ··· 61 BUG_ON(t == NULL); 62 off = ALIGN(sizeof(struct nf_ct_ext), t->align); 63 len = off + t->len; 64 rcu_read_unlock(); 65 66 + *ext = kzalloc(t->alloc_size, gfp); 67 if (!*ext) 68 return NULL; 69 70 (*ext)->offset[id] = off; 71 (*ext)->len = len; 72 73 return (void *)(*ext) + off; 74 } ··· 95 newlen = newoff + t->len; 96 rcu_read_unlock(); 97 98 + if (newlen >= ksize(ct->ext)) { 99 new = kmalloc(newlen, gfp); 100 if (!new) 101 return NULL; ··· 114 rcu_read_unlock(); 115 } 116 kfree(ct->ext); 117 ct->ext = new; 118 } 119 ··· 156 t1->alloc_size = ALIGN(t1->alloc_size, t2->align) 157 + t2->len; 158 } 159 } 160 } 161