@@ -161,16 +161,18 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
161
161
dev_err (dev , "memory alloc failed\n" );
162
162
ret = - ENOMEM ;
163
163
goto cleanup ;
164
+
164
165
}
165
166
166
- mmap_read_lock (current -> mm );
167
167
if (HAILO_DMA_DMABUF_BUFFER != buffer_type ) {
168
+ mmap_read_lock (current -> mm );
168
169
vma = find_vma (current -> mm , user_address );
170
+ mmap_read_unlock (current -> mm );
169
171
if (IS_ENABLED (HAILO_SUPPORT_MMIO_DMA_MAPPING )) {
170
172
if (NULL == vma ) {
171
173
dev_err (dev , "no vma for virt_addr/size = 0x%08lx/0x%08zx\n" , user_address , size );
172
174
ret = - EFAULT ;
173
- goto unlock_cleanup ;
175
+ goto cleanup ;
174
176
}
175
177
}
176
178
@@ -180,7 +182,7 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
180
182
ret = create_fd_from_vma (dev , vma );
181
183
if (ret < 0 ) {
182
184
dev_err (dev , "Failed creating fd from vma in given dmabuf\n" );
183
- goto unlock_cleanup ;
185
+ goto cleanup ;
184
186
}
185
187
// Override user address with fd to the dmabuf - like normal dmabuf flow
186
188
user_address = ret ;
@@ -213,7 +215,7 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
213
215
ret = hailo_map_dmabuf (dev , user_address , direction , & sgt , & dmabuf_info );
214
216
if (ret < 0 ) {
215
217
dev_err (dev , "Failed mapping dmabuf\n" );
216
- goto unlock_cleanup ;
218
+ goto cleanup ;
217
219
}
218
220
// If created dmabuf fd from vma need to decrement refcount and release fd
219
221
if (created_dmabuf_fd_from_vma ) {
@@ -235,8 +237,6 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
235
237
}
236
238
}
237
239
238
- mmap_read_unlock (current -> mm );
239
-
240
240
kref_init (& mapped_buffer -> kref );
241
241
mapped_buffer -> device = dev ;
242
242
mapped_buffer -> user_address = user_address ;
@@ -252,8 +252,6 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
252
252
clear_sg_table (& sgt );
253
253
free_buffer_struct :
254
254
kfree (mapped_buffer );
255
- unlock_cleanup :
256
- mmap_read_unlock (current -> mm );
257
255
cleanup :
258
256
return ERR_PTR (ret );
259
257
}
0 commit comments