@@ -1105,21 +1105,33 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1105
1105
if (obj_size < vma -> vm_end - vma -> vm_start )
1106
1106
return - EINVAL ;
1107
1107
1108
+ /* Take a ref for this mapping of the object, so that the fault
1109
+ * handler can dereference the mmap offset's pointer to the object.
1110
+ * This reference is cleaned up by the corresponding vm_close
1111
+ * (which should happen whether the vma was created by this call, or
1112
+ * by a vm_open due to mremap or partial unmap or whatever).
1113
+ */
1114
+ drm_gem_object_get (obj );
1115
+
1108
1116
if (obj -> funcs && obj -> funcs -> mmap ) {
1109
1117
/* Remove the fake offset */
1110
1118
vma -> vm_pgoff -= drm_vma_node_start (& obj -> vma_node );
1111
1119
1112
1120
ret = obj -> funcs -> mmap (obj , vma );
1113
- if (ret )
1121
+ if (ret ) {
1122
+ drm_gem_object_put_unlocked (obj );
1114
1123
return ret ;
1124
+ }
1115
1125
WARN_ON (!(vma -> vm_flags & VM_DONTEXPAND ));
1116
1126
} else {
1117
1127
if (obj -> funcs && obj -> funcs -> vm_ops )
1118
1128
vma -> vm_ops = obj -> funcs -> vm_ops ;
1119
1129
else if (dev -> driver -> gem_vm_ops )
1120
1130
vma -> vm_ops = dev -> driver -> gem_vm_ops ;
1121
- else
1131
+ else {
1132
+ drm_gem_object_put_unlocked (obj );
1122
1133
return - EINVAL ;
1134
+ }
1123
1135
1124
1136
vma -> vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP ;
1125
1137
vma -> vm_page_prot = pgprot_writecombine (vm_get_page_prot (vma -> vm_flags ));
@@ -1128,14 +1140,6 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1128
1140
1129
1141
vma -> vm_private_data = obj ;
1130
1142
1131
- /* Take a ref for this mapping of the object, so that the fault
1132
- * handler can dereference the mmap offset's pointer to the object.
1133
- * This reference is cleaned up by the corresponding vm_close
1134
- * (which should happen whether the vma was created by this call, or
1135
- * by a vm_open due to mremap or partial unmap or whatever).
1136
- */
1137
- drm_gem_object_get (obj );
1138
-
1139
1143
return 0 ;
1140
1144
}
1141
1145
EXPORT_SYMBOL (drm_gem_mmap_obj );
0 commit comments