diff options
author | Visa Hankala <visa@cvs.openbsd.org> | 2021-11-06 05:26:34 +0000 |
---|---|---|
committer | Visa Hankala <visa@cvs.openbsd.org> | 2021-11-06 05:26:34 +0000 |
commit | 050fdf90f8fece4f71708c1c4b9da22eb0e54775 (patch) | |
tree | 4b95810071cc86f4d428a8814b063f420a581388 /sys/kern | |
parent | 447e4ee17bda5f288d7e640d8b61378c06fa0d35 (diff) |
Allocate socket and initialize so_lock in one place
This makes witness(4) use a single lock type for tracking so_lock.
Previously, so_lock was covered by two distinct lock types because there
were separate rw_init() initializers in socreate() and sonewconn().
OK kettenis@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/uipc_socket.c | 17 | ||||
-rw-r--r-- | sys/kern/uipc_socket2.c | 5 |
2 files changed, 16 insertions, 6 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index f0d7046c40c..56d3098a6fd 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.267 2021/10/24 07:02:47 visa Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.268 2021/11/06 05:26:33 visa Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -148,6 +148,18 @@ soinit(void) #endif } +struct socket * +soalloc(int prflags) +{ + struct socket *so; + + so = pool_get(&socket_pool, prflags); + if (so == NULL) + return (NULL); + rw_init(&so->so_lock, "solock"); + return (so); +} + /* * Socket operation routines. * These routines are called by the routines in @@ -171,8 +183,7 @@ socreate(int dom, struct socket **aso, int type, int proto) return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); - so = pool_get(&socket_pool, PR_WAITOK | PR_ZERO); - rw_init(&so->so_lock, "solock"); + so = soalloc(PR_WAITOK | PR_ZERO); klist_init(&so->so_rcv.sb_sel.si_note, &socket_klistops, so); klist_init(&so->so_snd.sb_sel.si_note, &socket_klistops, so); sigio_init(&so->so_sigio); diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 66c76560958..42a61e60bd2 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.115 2021/10/27 13:41:09 mvs Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.116 2021/11/06 05:26:33 visa Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -159,10 +159,9 @@ sonewconn(struct socket *head, int connstatus) return (NULL); if (head->so_qlen + head->so_q0len > head->so_qlimit * 3) return (NULL); - so = pool_get(&socket_pool, PR_NOWAIT|PR_ZERO); + so = soalloc(PR_NOWAIT | PR_ZERO); if (so == NULL) return (NULL); - rw_init(&so->so_lock, "solock"); so->so_type = head->so_type; so->so_options = head->so_options &~ SO_ACCEPTCONN; so->so_linger = head->so_linger; |