diff options
| -rw-r--r-- | drivers/base/dma-buf.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 394523807a6d..2a7cb0df176b 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c | |||
| @@ -447,6 +447,9 @@ EXPORT_SYMBOL_GPL(dma_buf_kunmap); | |||
| 447 | int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, | 447 | int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, |
| 448 | unsigned long pgoff) | 448 | unsigned long pgoff) |
| 449 | { | 449 | { |
| 450 | struct file *oldfile; | ||
| 451 | int ret; | ||
| 452 | |||
| 450 | if (WARN_ON(!dmabuf || !vma)) | 453 | if (WARN_ON(!dmabuf || !vma)) |
| 451 | return -EINVAL; | 454 | return -EINVAL; |
| 452 | 455 | ||
| @@ -460,14 +463,22 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, | |||
| 460 | return -EINVAL; | 463 | return -EINVAL; |
| 461 | 464 | ||
| 462 | /* readjust the vma */ | 465 | /* readjust the vma */ |
| 463 | if (vma->vm_file) | 466 | get_file(dmabuf->file); |
| 464 | fput(vma->vm_file); | 467 | oldfile = vma->vm_file; |
| 465 | 468 | vma->vm_file = dmabuf->file; | |
| 466 | vma->vm_file = get_file(dmabuf->file); | ||
| 467 | |||
| 468 | vma->vm_pgoff = pgoff; | 469 | vma->vm_pgoff = pgoff; |
| 469 | 470 | ||
| 470 | return dmabuf->ops->mmap(dmabuf, vma); | 471 | ret = dmabuf->ops->mmap(dmabuf, vma); |
| 472 | if (ret) { | ||
| 473 | /* restore old parameters on failure */ | ||
| 474 | vma->vm_file = oldfile; | ||
| 475 | fput(dmabuf->file); | ||
| 476 | } else { | ||
| 477 | if (oldfile) | ||
| 478 | fput(oldfile); | ||
| 479 | } | ||
| 480 | return ret; | ||
| 481 | |||
| 471 | } | 482 | } |
| 472 | EXPORT_SYMBOL_GPL(dma_buf_mmap); | 483 | EXPORT_SYMBOL_GPL(dma_buf_mmap); |
| 473 | 484 | ||
