Skip to content

Commit e697a3b

Browse files
naushirpopcornmix
authored andcommitted
drivers: pci: hailo: Better lock handling when calling find_vdma()
Due to possible instabilities, reduce the mmap read lock time to only cover the call to find_vdma(). Signed-off-by: Naushir Patuck <[email protected]>
1 parent e7cfb84 commit e697a3b

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

drivers/media/pci/hailo/vdma/memory.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,18 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
161161
dev_err(dev, "memory alloc failed\n");
162162
ret = -ENOMEM;
163163
goto cleanup;
164+
164165
}
165166

166-
mmap_read_lock(current->mm);
167167
if (HAILO_DMA_DMABUF_BUFFER != buffer_type) {
168+
mmap_read_lock(current->mm);
168169
vma = find_vma(current->mm, user_address);
170+
mmap_read_unlock(current->mm);
169171
if (IS_ENABLED(HAILO_SUPPORT_MMIO_DMA_MAPPING)) {
170172
if (NULL == vma) {
171173
dev_err(dev, "no vma for virt_addr/size = 0x%08lx/0x%08zx\n", user_address, size);
172174
ret = -EFAULT;
173-
goto unlock_cleanup;
175+
goto cleanup;
174176
}
175177
}
176178

@@ -180,7 +182,7 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
180182
ret = create_fd_from_vma(dev, vma);
181183
if (ret < 0) {
182184
dev_err(dev, "Failed creating fd from vma in given dmabuf\n");
183-
goto unlock_cleanup;
185+
goto cleanup;
184186
}
185187
// Override user address with fd to the dmabuf - like normal dmabuf flow
186188
user_address = ret;
@@ -213,7 +215,7 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
213215
ret = hailo_map_dmabuf(dev, user_address, direction, &sgt, &dmabuf_info);
214216
if (ret < 0) {
215217
dev_err(dev, "Failed mapping dmabuf\n");
216-
goto unlock_cleanup;
218+
goto cleanup;
217219
}
218220
// If created dmabuf fd from vma need to decrement refcount and release fd
219221
if (created_dmabuf_fd_from_vma) {
@@ -235,8 +237,6 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
235237
}
236238
}
237239

238-
mmap_read_unlock(current->mm);
239-
240240
kref_init(&mapped_buffer->kref);
241241
mapped_buffer->device = dev;
242242
mapped_buffer->user_address = user_address;
@@ -252,8 +252,6 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
252252
clear_sg_table(&sgt);
253253
free_buffer_struct:
254254
kfree(mapped_buffer);
255-
unlock_cleanup:
256-
mmap_read_unlock(current->mm);
257255
cleanup:
258256
return ERR_PTR(ret);
259257
}

0 commit comments

Comments
 (0)