From: mvs Date: Sun, 2 May 2021 14:22:05 +0000 (+0000) Subject: Do soreserve() before `kp' allocation. This simplifies error path. The X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=891dfedc260602a4b08b493c26b4b2e8d6f72c1c;p=openbsd Do soreserve() before `kp' allocation. This simplifies error path. The same was done for route_attach(). Also do soisconnected() after `kp' is fully initialized. This chair movement affects nothing for PF_KEY sockets but makes code more consistent. ok bluhm@ mpi@ --- diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index a757bf04d8e..e03c899eaa7 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.208 2020/12/14 20:20:06 tobhe Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.209 2021/05/02 14:22:05 mvs Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -269,24 +269,20 @@ pfkeyv2_attach(struct socket *so, int proto) if ((so->so_state & SS_PRIV) == 0) return EACCES; - kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO); - so->so_pcb = kp; - refcnt_init(&kp->kcb_refcnt); - error = soreserve(so, PFKEYSNDQ, PFKEYRCVQ); - if (error) { - pool_put(&pkpcb_pool, kp); + if (error) return (error); - } + kp = pool_get(&pkpcb_pool, PR_WAITOK|PR_ZERO); + so->so_pcb = kp; + refcnt_init(&kp->kcb_refcnt); kp->kcb_socket = so; + kp->kcb_pid = curproc->p_p->ps_pid; + kp->kcb_rdomain = rtable_l2(curproc->p_p->ps_rtableid); so->so_options |= SO_USELOOPBACK; soisconnected(so); - kp->kcb_pid = curproc->p_p->ps_pid; - kp->kcb_rdomain = rtable_l2(curproc->p_p->ps_rtableid); - rw_enter(&pkptable.pkp_lk, RW_WRITE); SRPL_INSERT_HEAD_LOCKED(&pkptable.pkp_rc, &pkptable.pkp_list, kp, kcb_list); rw_exit(&pkptable.pkp_lk);