Skip to content

Commit fd21150

Browse files
tgrafDavid S. Miller
authored andcommitted
[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>
1 parent 15901a2 commit fd21150

1 file changed

Lines changed: 17 additions & 49 deletions

File tree

‎net/xfrm/xfrm_user.c‎

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,6 @@ static int attach_one_algo(struct xfrm_algo **algpp, u8 *props,
214214
return 0;
215215
}
216216

217-
static 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-
234217
static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx)
235218
{
236219
int len = 0;
@@ -242,33 +225,6 @@ static inline int xfrm_user_sec_ctx_size(struct xfrm_sec_ctx *xfrm_ctx)
242225
return len;
243226
}
244227

245-
static 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-
256-
static 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-
272228
static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
273229
{
274230
memcpy(&x->id, &p->id, sizeof(x->id));
@@ -348,15 +304,27 @@ static struct xfrm_state *xfrm_state_construct(struct xfrm_usersa_info *p,
348304
xfrm_calg_get_byname,
349305
attrs[XFRMA_ALG_COMP])))
350306
goto error;
351-
if ((err = attach_encap_tmpl(&x->encap, attrs[XFRMA_ENCAP])))
352-
goto error;
353-
if ((err = attach_one_addr(&x->coaddr, attrs[XFRMA_COADDR])))
354-
goto error;
307+
308+
if (attrs[XFRMA_ENCAP]) {
309+
x->encap = kmemdup(nla_data(attrs[XFRMA_ENCAP]),
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+
355322
err = xfrm_init_state(x);
356323
if (err)
357324
goto error;
358325

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])))
360328
goto error;
361329

362330
x->km.seq = p->seq;

0 commit comments

Comments
 (0)