aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2026-08-10 14:41:22 +0000
committerMark Johnston <markj@FreeBSD.org>2026-08-10 17:31:21 +0000
commite27d36e038bf0d681d19a07d3512e0dc5adb20c7 (patch)
treefe0715e6b65ec476647c9a8434dc57196caff3a4
parent6dfd710963da7fe6086bcfb705b32b6a3646848f (diff)
unix: Simplify uipc_detach()
uipc_close() handles detaching a unix socket from the vnode to which it's bound, if any, so doing the same in uipc_detach() is redundant. Moreover, it's conceptually wrong that uipc_detach() might need to handle this: detach happens when there are no remaining references to the socket, and that should include the vnode's reference, even though it's not explicitly counted. No functional change intended. Reviewed by: John Ericson <inquire@JohnEricson.me>, glebius MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58675
-rw-r--r--sys/kern/uipc_usrreq.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 835daa09fc9a..df9568015724 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -802,15 +802,10 @@ static void
uipc_detach(struct socket *so)
{
struct unpcb *unp, *unp2;
- struct mtx *vplock;
- struct vnode *vp;
unp = sotounpcb(so);
KASSERT(unp != NULL, ("uipc_detach: unp == NULL"));
- vp = NULL;
- vplock = NULL;
-
if (!SOLISTENING(so))
unp_dispose(so);
@@ -822,23 +817,9 @@ uipc_detach(struct socket *so)
--unp_count;
UNP_LINK_WUNLOCK();
- UNP_PCB_UNLOCK_ASSERT(unp);
- restart:
- if ((vp = unp->unp_vnode) != NULL) {
- vplock = mtx_pool_find(unp_vp_mtxpool, vp);
- mtx_lock(vplock);
- }
UNP_PCB_LOCK(unp);
- if (unp->unp_vnode != vp && unp->unp_vnode != NULL) {
- if (vplock)
- mtx_unlock(vplock);
- UNP_PCB_UNLOCK(unp);
- goto restart;
- }
- if ((vp = unp->unp_vnode) != NULL) {
- VOP_UNP_DETACH(vp);
- unp->unp_vnode = NULL;
- }
+ KASSERT(unp->unp_vnode == NULL,
+ ("%s: unp %p has vnode", __func__, unp));
if ((unp2 = unp_pcb_lock_peer(unp)) != NULL)
unp_disconnect(unp, unp2);
else
@@ -865,10 +846,7 @@ uipc_detach(struct socket *so)
unp->unp_addr = NULL;
if (!unp_pcb_rele(unp))
UNP_PCB_UNLOCK(unp);
- if (vp) {
- mtx_unlock(vplock);
- vrele(vp);
- }
+
maybe_schedule_gc();
switch (so->so_type) {