From 03cc3716140e9694c1224dfe773f69902396c9e9 Mon Sep 17 00:00:00 2001 From: John Sheu Date: Mon, 11 Feb 2013 17:50:24 -0800 Subject: [PATCH] --- yaml --- r: 359751 b: refs/heads/master c: 495c10cc1c0c359871d5bef32dd173252fc17995 h: refs/heads/master i: 359749: d61eb6939febb8397ab1a3352e661ac71036889e 359747: 5024aed85f28ad4b0f21f28391060ca61562a293 359743: feda94258ab8682e3ee952551cb07f507ac295c5 v: v3 --- [refs] | 2 +- trunk/drivers/base/dma-buf.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/[refs] b/[refs] index 9effbbfea81a..f0545dc293f2 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: f00b4dad9d9eb001a04cf72e8351a2a1b9e99322 +refs/heads/master: 495c10cc1c0c359871d5bef32dd173252fc17995 diff --git a/trunk/drivers/base/dma-buf.c b/trunk/drivers/base/dma-buf.c index 394523807a6d..2a7cb0df176b 100644 --- a/trunk/drivers/base/dma-buf.c +++ b/trunk/drivers/base/dma-buf.c @@ -447,6 +447,9 @@ EXPORT_SYMBOL_GPL(dma_buf_kunmap); 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; @@ -460,14 +463,22 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, return -EINVAL; /* readjust the vma */ - if (vma->vm_file) - 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);