diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2009-01-05 00:43:23 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-01-05 00:43:23 -0500 |
commit | e5fd56ca4eb3a130882bbef69d6952ef6aca5c8d (patch) | |
tree | 4e0c6670335f2434fbe8f44554988ca9832a685a /net/dccp/ccid.c | |
parent | ddebc973c56b51b4e5d84d606f0430d81b895d67 (diff) |
dccp: Clean up ccid.c after integration of CCID plugins
This patch cleans up after integrating the CCID modules and, in addition,
* moves the if/else cases from ccid_delete() into ccid_hc_{tx,rx}_delete();
* removes the 'gfp' argument to ccid_new() - since it is always gfp_any().
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/ccid.c')
-rw-r--r-- | net/dccp/ccid.c | 136 |
1 files changed, 12 insertions, 124 deletions
diff --git a/net/dccp/ccid.c b/net/dccp/ccid.c index 538d3b1da623..19b214ad5e06 100644 --- a/net/dccp/ccid.c +++ b/net/dccp/ccid.c | |||
@@ -76,58 +76,6 @@ int ccid_getsockopt_builtin_ccids(struct sock *sk, int len, | |||
76 | return err; | 76 | return err; |
77 | } | 77 | } |
78 | 78 | ||
79 | #ifdef ___OLD_INTERFACE_TO_BE_REMOVED___ | ||
80 | static u8 builtin_ccids[] = { | ||
81 | DCCPC_CCID2, /* CCID2 is supported by default */ | ||
82 | #if defined(CONFIG_IP_DCCP_CCID3) || defined(CONFIG_IP_DCCP_CCID3_MODULE) | ||
83 | DCCPC_CCID3, | ||
84 | #endif | ||
85 | }; | ||
86 | |||
87 | static struct ccid_operations *ccids[CCID_MAX]; | ||
88 | #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) | ||
89 | static atomic_t ccids_lockct = ATOMIC_INIT(0); | ||
90 | static DEFINE_SPINLOCK(ccids_lock); | ||
91 | |||
92 | /* | ||
93 | * The strategy is: modifications ccids vector are short, do not sleep and | ||
94 | * veeery rare, but read access should be free of any exclusive locks. | ||
95 | */ | ||
96 | static void ccids_write_lock(void) | ||
97 | { | ||
98 | spin_lock(&ccids_lock); | ||
99 | while (atomic_read(&ccids_lockct) != 0) { | ||
100 | spin_unlock(&ccids_lock); | ||
101 | yield(); | ||
102 | spin_lock(&ccids_lock); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | static inline void ccids_write_unlock(void) | ||
107 | { | ||
108 | spin_unlock(&ccids_lock); | ||
109 | } | ||
110 | |||
111 | static inline void ccids_read_lock(void) | ||
112 | { | ||
113 | atomic_inc(&ccids_lockct); | ||
114 | smp_mb__after_atomic_inc(); | ||
115 | spin_unlock_wait(&ccids_lock); | ||
116 | } | ||
117 | |||
118 | static inline void ccids_read_unlock(void) | ||
119 | { | ||
120 | atomic_dec(&ccids_lockct); | ||
121 | } | ||
122 | |||
123 | #else | ||
124 | #define ccids_write_lock() do { } while(0) | ||
125 | #define ccids_write_unlock() do { } while(0) | ||
126 | #define ccids_read_lock() do { } while(0) | ||
127 | #define ccids_read_unlock() do { } while(0) | ||
128 | #endif | ||
129 | #endif /* ___OLD_INTERFACE_TO_BE_REMOVED___ */ | ||
130 | |||
131 | static struct kmem_cache *ccid_kmem_cache_create(int obj_size, const char *fmt,...) | 79 | static struct kmem_cache *ccid_kmem_cache_create(int obj_size, const char *fmt,...) |
132 | { | 80 | { |
133 | struct kmem_cache *slab; | 81 | struct kmem_cache *slab; |
@@ -158,49 +106,6 @@ static void ccid_kmem_cache_destroy(struct kmem_cache *slab) | |||
158 | } | 106 | } |
159 | } | 107 | } |
160 | 108 | ||
161 | #ifdef ___OLD_INTERFACE_TO_BE_REMOVED___ | ||
162 | /* check that up to @array_len members in @ccid_array are supported */ | ||
163 | bool ccid_support_check(u8 const *ccid_array, u8 array_len) | ||
164 | { | ||
165 | u8 i, j, found; | ||
166 | |||
167 | for (i = 0, found = 0; i < array_len; i++, found = 0) { | ||
168 | for (j = 0; !found && j < ARRAY_SIZE(builtin_ccids); j++) | ||
169 | found = (ccid_array[i] == builtin_ccids[j]); | ||
170 | if (!found) | ||
171 | return false; | ||
172 | } | ||
173 | return true; | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * ccid_get_builtin_ccids - Provide copy of `builtin' CCID array | ||
178 | * @ccid_array: pointer to copy into | ||
179 | * @array_len: value to return length into | ||
180 | * This function allocates memory - caller must see that it is freed after use. | ||
181 | */ | ||
182 | int ccid_get_builtin_ccids(u8 **ccid_array, u8 *array_len) | ||
183 | { | ||
184 | *ccid_array = kmemdup(builtin_ccids, sizeof(builtin_ccids), gfp_any()); | ||
185 | if (*ccid_array == NULL) | ||
186 | return -ENOBUFS; | ||
187 | *array_len = ARRAY_SIZE(builtin_ccids); | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | int ccid_getsockopt_builtin_ccids(struct sock *sk, int len, | ||
192 | char __user *optval, int __user *optlen) | ||
193 | { | ||
194 | if (len < sizeof(builtin_ccids)) | ||
195 | return -EINVAL; | ||
196 | |||
197 | if (put_user(sizeof(builtin_ccids), optlen) || | ||
198 | copy_to_user(optval, builtin_ccids, sizeof(builtin_ccids))) | ||
199 | return -EFAULT; | ||
200 | return 0; | ||
201 | } | ||
202 | #endif /* ___OLD_INTERFACE_TO_BE_REMOVED___ */ | ||
203 | |||
204 | static int ccid_activate(struct ccid_operations *ccid_ops) | 109 | static int ccid_activate(struct ccid_operations *ccid_ops) |
205 | { | 110 | { |
206 | int err = -ENOBUFS; | 111 | int err = -ENOBUFS; |
@@ -241,7 +146,7 @@ static void ccid_deactivate(struct ccid_operations *ccid_ops) | |||
241 | ccid_ops->ccid_id, ccid_ops->ccid_name); | 146 | ccid_ops->ccid_id, ccid_ops->ccid_name); |
242 | } | 147 | } |
243 | 148 | ||
244 | struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, gfp_t gfp) | 149 | struct ccid *ccid_new(const u8 id, struct sock *sk, bool rx) |
245 | { | 150 | { |
246 | struct ccid_operations *ccid_ops = ccid_by_number(id); | 151 | struct ccid_operations *ccid_ops = ccid_by_number(id); |
247 | struct ccid *ccid = NULL; | 152 | struct ccid *ccid = NULL; |
@@ -250,7 +155,7 @@ struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, gfp_t gfp) | |||
250 | goto out; | 155 | goto out; |
251 | 156 | ||
252 | ccid = kmem_cache_alloc(rx ? ccid_ops->ccid_hc_rx_slab : | 157 | ccid = kmem_cache_alloc(rx ? ccid_ops->ccid_hc_rx_slab : |
253 | ccid_ops->ccid_hc_tx_slab, gfp); | 158 | ccid_ops->ccid_hc_tx_slab, gfp_any()); |
254 | if (ccid == NULL) | 159 | if (ccid == NULL) |
255 | goto out; | 160 | goto out; |
256 | ccid->ccid_ops = ccid_ops; | 161 | ccid->ccid_ops = ccid_ops; |
@@ -274,41 +179,24 @@ out_free_ccid: | |||
274 | goto out; | 179 | goto out; |
275 | } | 180 | } |
276 | 181 | ||
277 | EXPORT_SYMBOL_GPL(ccid_new); | ||
278 | |||
279 | static void ccid_delete(struct ccid *ccid, struct sock *sk, int rx) | ||
280 | { | ||
281 | struct ccid_operations *ccid_ops; | ||
282 | |||
283 | if (ccid == NULL) | ||
284 | return; | ||
285 | |||
286 | ccid_ops = ccid->ccid_ops; | ||
287 | if (rx) { | ||
288 | if (ccid_ops->ccid_hc_rx_exit != NULL) | ||
289 | ccid_ops->ccid_hc_rx_exit(sk); | ||
290 | kmem_cache_free(ccid_ops->ccid_hc_rx_slab, ccid); | ||
291 | } else { | ||
292 | if (ccid_ops->ccid_hc_tx_exit != NULL) | ||
293 | ccid_ops->ccid_hc_tx_exit(sk); | ||
294 | kmem_cache_free(ccid_ops->ccid_hc_tx_slab, ccid); | ||
295 | } | ||
296 | } | ||
297 | |||
298 | void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk) | 182 | void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk) |
299 | { | 183 | { |
300 | ccid_delete(ccid, sk, 1); | 184 | if (ccid != NULL) { |
185 | if (ccid->ccid_ops->ccid_hc_rx_exit != NULL) | ||
186 | ccid->ccid_ops->ccid_hc_rx_exit(sk); | ||
187 | kmem_cache_free(ccid->ccid_ops->ccid_hc_rx_slab, ccid); | ||
188 | } | ||
301 | } | 189 | } |
302 | 190 | ||
303 | EXPORT_SYMBOL_GPL(ccid_hc_rx_delete); | ||
304 | |||
305 | void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk) | 191 | void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk) |
306 | { | 192 | { |
307 | ccid_delete(ccid, sk, 0); | 193 | if (ccid != NULL) { |
194 | if (ccid->ccid_ops->ccid_hc_tx_exit != NULL) | ||
195 | ccid->ccid_ops->ccid_hc_tx_exit(sk); | ||
196 | kmem_cache_free(ccid->ccid_ops->ccid_hc_tx_slab, ccid); | ||
197 | } | ||
308 | } | 198 | } |
309 | 199 | ||
310 | EXPORT_SYMBOL_GPL(ccid_hc_tx_delete); | ||
311 | |||
312 | int __init ccid_initialize_builtins(void) | 200 | int __init ccid_initialize_builtins(void) |
313 | { | 201 | { |
314 | int i, err; | 202 | int i, err; |