diff options
author | Mark Johnston <markj@FreeBSD.org> | 2024-08-28 18:57:21 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2024-08-28 18:57:21 +0000 |
commit | f4002135a2be59272f39f886fb270f5a4736ac08 (patch) | |
tree | c1ccec607c11ef45f5232fbcc7dcf709ed782cb3 | |
parent | 063a8bd908ddaae9f0ba8c7711dfe837a14f21e7 (diff) | |
download | src-f4002135a2be59272f39f886fb270f5a4736ac08.tar.gz src-f4002135a2be59272f39f886fb270f5a4736ac08.zip |
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
-rw-r--r-- | sys/dev/vmm/vmm_dev.c | 13 |
1 files 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); |