From d56f1ed8871dde297962cf01a091428f6a1b20cd Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Wed, 31 May 2017 13:07:05 +0000 Subject: [PATCH] Make sure the VMAP's "vm_file" field is referenced in a Linux compatible way by the linux_dev_mmap_single() function in the LinuxKPI. MFC after: 1 week Sponsored by: Mellanox Technologies --- sys/compat/linuxkpi/common/src/linux_compat.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 7deb315ee7a6..12dbdf57d46d 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -489,6 +489,10 @@ static TAILQ_HEAD(, vm_area_struct) linux_vma_head = static void linux_cdev_handle_free(struct vm_area_struct *vmap) { + /* Drop reference on vm_file */ + if (vmap->vm_file != NULL) + fput(vmap->vm_file); + /* Drop reference on mm_struct */ mmput(vmap->vm_mm); @@ -931,7 +935,7 @@ linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *offset, vmap->vm_pfn = 0; vmap->vm_flags = vmap->vm_page_prot = nprot; vmap->vm_ops = NULL; - vmap->vm_file = filp; + vmap->vm_file = get_file(filp); vmap->vm_mm = mm; if (unlikely(down_write_killable(&vmap->vm_mm->mmap_sem))) {