git: f4002135a2be - main - vmm: Remove an unneeded lookup in devmem_create_cdev()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 28 Aug 2024 19:12:44 UTC
The branch main has been updated by markj:

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

commit f4002135a2be59272f39f886fb270f5a4736ac08
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-08-28 18:57:21 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-08-28 18:57:21 +0000

    vmm: Remove an unneeded lookup in devmem_create_cdev()
    
    The sole caller of this function already holds a pointer to the VM's
    softc, so rather than passing the VM name and looking it up again, just
    pass the softc pointer directly.  This function is only called from an
    ioctl context, so the softc structure will remain live.
    
    Reviewed by:    corvink, jhb
    Differential Revision:  https://reviews.freebsd.org/D46446
---
 sys/dev/vmm/vmm_dev.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/sys/dev/vmm/vmm_dev.c b/sys/dev/vmm/vmm_dev.c
index 6bdcb51777d4..c42b2aaee5ed 100644
--- a/sys/dev/vmm/vmm_dev.c
+++ b/sys/dev/vmm/vmm_dev.c
@@ -42,8 +42,6 @@ _Static_assert(sizeof(struct vm_memseg_fbsd12) == 80, "COMPAT_FREEBSD12 ABI");
 	_IOWR('v', IOCNUM_GET_MEMSEG, struct vm_memseg_fbsd12)
 #endif
 
-static int devmem_create_cdev(const char *vmname, int id, char *devmem);
-
 struct devmem_softc {
 	int	segid;
 	char	*name;
@@ -73,6 +71,7 @@ static MALLOC_DEFINE(M_VMMDEV, "vmmdev", "vmmdev");
 SYSCTL_DECL(_hw_vmm);
 
 static void devmem_destroy(void *arg);
+static int devmem_create_cdev(struct vmmdev_softc *sc, int id, char *devmem);
 
 static int
 vmm_priv_check(struct ucred *ucred)
@@ -287,7 +286,7 @@ alloc_memseg(struct vmmdev_softc *sc, struct vm_memseg *mseg, size_t len)
 		goto done;
 
 	if (VM_MEMSEG_NAME(mseg)) {
-		error = devmem_create_cdev(vm_name(sc->vm), mseg->segid, name);
+		error = devmem_create_cdev(sc, mseg->segid, name);
 		if (error)
 			vm_free_memseg(sc->vm, mseg->segid);
 		else
@@ -989,13 +988,15 @@ static struct cdevsw devmemsw = {
 };
 
 static int
-devmem_create_cdev(const char *vmname, int segid, char *devname)
+devmem_create_cdev(struct vmmdev_softc *sc, int segid, char *devname)
 {
 	struct devmem_softc *dsc;
-	struct vmmdev_softc *sc;
 	struct cdev *cdev;
+	const char *vmname;
 	int error;
 
+	vmname = vm_name(sc->vm);
+
 	error = make_dev_p(MAKEDEV_CHECKNAME, &cdev, &devmemsw, NULL,
 	    UID_ROOT, GID_WHEEL, 0600, "vmm.io/%s.%s", vmname, devname);
 	if (error)
@@ -1004,8 +1005,6 @@ devmem_create_cdev(const char *vmname, int segid, char *devname)
 	dsc = malloc(sizeof(struct devmem_softc), M_VMMDEV, M_WAITOK | M_ZERO);
 
 	mtx_lock(&vmmdev_mtx);
-	sc = vmmdev_lookup(vmname);
-	KASSERT(sc != NULL, ("%s: vm %s softc not found", __func__, vmname));
 	if (sc->cdev == NULL) {
 		/* virtual machine is being created or destroyed */
 		mtx_unlock(&vmmdev_mtx);