*
* 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
* 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) {
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");
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;
}
*
* 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
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