]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
Revert "mm: mmap: fix fput in error path v2"
authorChristian König <christian.koenig@amd.com>
Thu, 5 Nov 2020 16:06:30 +0000 (17:06 +0100)
committerChristian König <christian.koenig@amd.com>
Thu, 5 Nov 2020 16:09:18 +0000 (17:09 +0100)
The kernel test robot is not happy with that.

This reverts commit 0227da01f2559626396af5f6c7453360db86c1f6.

Signed-off-by: Christian König <christian.koenig@amd.com>
Acked-by: Daniel Vetter <daniel@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/394772/
drivers/dma-buf/dma-buf.c
mm/mmap.c

index 282bd8b8417088c850d18a4f942181945f6157ef..0eb80c1ecdab3ddc790fd8677fd8566e2f127877 100644 (file)
@@ -1166,6 +1166,9 @@ EXPORT_SYMBOL_GPL(dma_buf_end_cpu_access);
 int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
                 unsigned long pgoff)
 {
+       struct file *oldfile;
+       int ret;
+
        if (WARN_ON(!dmabuf || !vma))
                return -EINVAL;
 
@@ -1183,11 +1186,22 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
                return -EINVAL;
 
        /* readjust the vma */
-       fput(vma->vm_file);
-       vma->vm_file = get_file(dmabuf->file);
+       get_file(dmabuf->file);
+       oldfile = vma->vm_file;
+       vma->vm_file = dmabuf->file;
        vma->vm_pgoff = pgoff;
 
-       return dmabuf->ops->mmap(dmabuf, vma);
+       ret = dmabuf->ops->mmap(dmabuf, vma);
+       if (ret) {
+               /* restore old parameters on failure */
+               vma->vm_file = oldfile;
+               fput(dmabuf->file);
+       } else {
+               if (oldfile)
+                       fput(oldfile);
+       }
+       return ret;
+
 }
 EXPORT_SYMBOL_GPL(dma_buf_mmap);
 
index 30a4e8412a585c1a7623a07677a30d152a764306..d91ecb00d38cd9733905d7f4fcaa8e2a6cfb222e 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1899,8 +1899,8 @@ out:
        return addr;
 
 unmap_and_free_vma:
-       fput(vma->vm_file);
        vma->vm_file = NULL;
+       fput(file);
 
        /* Undo any partial mapping done by a device driver. */
        unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);