summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/video/tegra/nvmap/nvmap_dev.c17
-rw-r--r--drivers/video/tegra/nvmap/nvmap_priv.h3
2 files changed, 15 insertions, 5 deletions
diff --git a/drivers/video/tegra/nvmap/nvmap_dev.c b/drivers/video/tegra/nvmap/nvmap_dev.c
index d90fc4a417ba..d1de4dce9336 100644
--- a/drivers/video/tegra/nvmap/nvmap_dev.c
+++ b/drivers/video/tegra/nvmap/nvmap_dev.c
@@ -3,7 +3,7 @@
*
* User-space interface to nvmap
*
- * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
+ * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -645,7 +645,12 @@ void nvmap_vma_open(struct vm_area_struct *vma)
* handle offsets
*/
list_for_each_entry(tmp, &h->vmas, list) {
- BUG_ON(tmp->vma == vma);
+ /* if vma exits in list, just increment refcount */
+ if (tmp->vma == vma) {
+ atomic_inc(&tmp->ref);
+ kfree(vma_list);
+ goto unlock;
+ }
if (!vma_pos_found && (current_pid == tmp->pid)) {
if (vma->vm_pgoff < tmp->vma->vm_pgoff) {
@@ -659,7 +664,9 @@ void nvmap_vma_open(struct vm_area_struct *vma)
vma_list->vma = vma;
vma_list->pid = current_pid;
+ atomic_set(&vma_list->ref, 1);
list_add_tail(&vma_list->list, tmp_head);
+unlock:
mutex_unlock(&h->lock);
} else {
WARN(1, "vma not tracked");
@@ -683,8 +690,10 @@ static void nvmap_vma_close(struct vm_area_struct *vma)
list_for_each_entry(vma_list, &h->vmas, list) {
if (vma_list->vma != vma)
continue;
- list_del(&vma_list->list);
- kfree(vma_list);
+ if (atomic_dec_return(&vma_list->ref) == 0) {
+ list_del(&vma_list->list);
+ kfree(vma_list);
+ }
vma_found = true;
break;
}
diff --git a/drivers/video/tegra/nvmap/nvmap_priv.h b/drivers/video/tegra/nvmap/nvmap_priv.h
index 977897a61aa2..a90a3269cd62 100644
--- a/drivers/video/tegra/nvmap/nvmap_priv.h
+++ b/drivers/video/tegra/nvmap/nvmap_priv.h
@@ -3,7 +3,7 @@
*
* GPU memory management driver for Tegra
*
- * Copyright (c) 2009-2014, NVIDIA CORPORATION. All rights reserved.
+ * Copyright (c) 2009-2016, NVIDIA CORPORATION. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -91,6 +91,7 @@ struct nvmap_vma_list {
struct list_head list;
struct vm_area_struct *vma;
pid_t pid;
+ atomic_t ref;
};
/* handles allocated using shared system memory (either IOVMM- or high-order