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