aboutsummaryrefslogtreecommitdiffstats
path: root/net/xfrm/xfrm_user.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2007-09-06 06:28:08 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:48:26 -0400
commitfd21150a0fe10c504160db359a4eb425576f6e7d (patch)
treefb1c912e8cb1867216f30d0c34f3b1f5427896ac /net/xfrm/xfrm_user.c
parent15901a2746e6a2dbe03043609f1575c2bcf726e8 (diff)
[XFRM] netlink: Inline attach_encap_tmpl(), attach_sec_ctx(), and attach_one_addr()
These functions are only used once and are a lot easier to understand if inlined directly into the function. Fixes by Masahide NAKAMURA. Signed-off-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm/xfrm_user.c')
-rw-r--r--net/xfrm/xfrm_user.c66
1 files changed, 17 insertions, 49 deletions
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index 70dca1e48242..9e516f5cbb5e 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -214,23 +214,6 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
214 return 0; 214 return 0;
215} 215}
216 216
217static int attach_encap_tmpl(struct xfrm_encap_tmpl **encapp, struct nlattr *rta)
218{
219 struct xfrm_encap_tmpl *p, *uencap;
220
221 if (!rta)
222 return 0;
223
224 uencap = nla_data(rta);
225 p = kmemdup(uencap, sizeof(*p), GFP_KERNEL);
226 if (!p)
227 return -ENOMEM;
228
229 *encapp = p;
230 return 0;
231}
232
233
234static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx) 217static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx)
235{ 218{
236 int len = 0; 219 int len = 0;
@@ -242,33 +225,6 @@ static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx)
242 return len; 225 return len;
243} 226}
244 227
245static int attach_sec_ctx(struct xfrm_state *x, struct nlattr *u_arg)
246{
247 struct xfrm_user_sec_ctx *uctx;
248
249 if (!u_arg)
250 return 0;
251
252 uctx = nla_data(u_arg);
253 return security_xfrm_state_alloc(x, uctx);
254}
255
256static int attach_one_addr(xfrm_address_t **addrpp, struct nlattr *rta)
257{
258 xfrm_address_t *p, *uaddrp;
259
260 if (!rta)
261 return 0;
262
263 uaddrp = nla_data(rta);
264 p = kmemdup(uaddrp, sizeof(*p), GFP_KERNEL);
265 if (!p)
266 return -ENOMEM;
267
268 *addrpp = p;
269 return 0;
270}
271
272static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p) 228static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
273{ 229{
274 memcpy(&x->id, &p->id, sizeof(x->id)); 230 memcpy(&x->id, &p->id, sizeof(x->id));
@@ -348,15 +304,27 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
348 xfrm_calg_get_byname, 304 xfrm_calg_get_byname,
349 attrs[XFRMA_ALG_COMP]))) 305 attrs[XFRMA_ALG_COMP])))
350 goto error; 306 goto error;
351 if ((err = attach_encap_tmpl(&x->encap, attrs[XFRMA_ENCAP]))) 307
352 goto error; 308 if (attrs[XFRMA_ENCAP]) {
353 if ((err = attach_one_addr(&x->coaddr, attrs[XFRMA_COADDR]))) 309 x->encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]),
354 goto error; 310 sizeof(*x->encap), GFP_KERNEL);
311 if (x->encap == NULL)
312 goto error;
313 }
314
315 if (attrs[XFRMA_COADDR]) {
316 x->coaddr = kmemdup(nla_data(attrs[XFRMA_COADDR]),
317 sizeof(*x->coaddr), GFP_KERNEL);
318 if (x->coaddr == NULL)
319 goto error;
320 }
321
355 err = xfrm_init_state(x); 322 err = xfrm_init_state(x);
356 if (err) 323 if (err)
357 goto error; 324 goto error;
358 325
359 if ((err = attach_sec_ctx(x, attrs[XFRMA_SEC_CTX]))) 326 if (attrs[XFRMA_SEC_CTX] &&
327 security_xfrm_state_alloc(x, nla_data(attrs[XFRMA_SEC_CTX])))
360 goto error; 328 goto error;
361 329
362 x->km.seq = p->seq; 330 x->km.seq = p->seq;