git: 1e2317b3bf1b - stable/14 - shm_alloc(): cleanup

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 15:05:39 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=1e2317b3bf1b33dd820d19cb2c1740818b176916

commit 1e2317b3bf1b33dd820d19cb2c1740818b176916
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-08 17:43:38 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-10-15 14:50:17 +0000

    shm_alloc(): cleanup
    
    (cherry picked from commit e578fd853a251c04d1eeb55c3aa499f8d0cb7480)
---
 sys/kern/uipc_shm.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c
index 8334d7eb3264..8a533428790a 100644
--- a/sys/kern/uipc_shm.c
+++ b/sys/kern/uipc_shm.c
@@ -944,24 +944,20 @@ shm_alloc(struct ucred *ucred, mode_t mode, bool largepage)
 	shmfd->shm_gid = ucred->cr_gid;
 	shmfd->shm_mode = mode;
 	if (largepage) {
-		obj = shmfd->shm_object = phys_pager_allocate(NULL,
-		    &shm_largepage_phys_ops, NULL, shmfd->shm_size,
-		    VM_PROT_DEFAULT, 0, ucred);
-		VM_OBJECT_WLOCK(shmfd->shm_object);
+		obj = phys_pager_allocate(NULL, &shm_largepage_phys_ops,
+		    NULL, shmfd->shm_size, VM_PROT_DEFAULT, 0, ucred);
 		obj->un_pager.phys.phys_priv = shmfd;
-		vm_object_set_flag(obj, OBJ_POSIXSHM);
-		VM_OBJECT_WUNLOCK(shmfd->shm_object);
 		shmfd->shm_lp_alloc_policy = SHM_LARGEPAGE_ALLOC_DEFAULT;
 	} else {
 		obj = vm_pager_allocate(shmfd_pager_type, NULL,
 		    shmfd->shm_size, VM_PROT_DEFAULT, 0, ucred);
-		VM_OBJECT_WLOCK(obj);
 		obj->un_pager.swp.swp_priv = shmfd;
-		vm_object_set_flag(obj, OBJ_POSIXSHM);
-		VM_OBJECT_WUNLOCK(obj);
-		shmfd->shm_object = obj;
 	}
-	KASSERT(shmfd->shm_object != NULL, ("shm_create: vm_pager_allocate"));
+	KASSERT(obj != NULL, ("shm_create: vm_pager_allocate"));
+	VM_OBJECT_WLOCK(obj);
+	vm_object_set_flag(obj, OBJ_POSIXSHM);
+	VM_OBJECT_WUNLOCK(obj);
+	shmfd->shm_object = obj;
 	vfs_timestamp(&shmfd->shm_birthtime);
 	shmfd->shm_atime = shmfd->shm_mtime = shmfd->shm_ctime =
 	    shmfd->shm_birthtime;