Skip to content

Commit 2d3b74b

Browse files
committed
drivers: pci: hailo: Fix kernel warning when calling find_vdma()
Calling this function without holding the mmap_read_lock causes the kernel to throw an error message, spamming the dmesg logs when running the Hailo hardware. Fix it by adding the approprite lock/unlock functions around find_vdma(). Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent 82ea131 commit 2d3b74b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,14 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
163163
goto cleanup;
164164
}
165165

166+
mmap_read_lock(current->mm);
166167
if (HAILO_DMA_DMABUF_BUFFER != buffer_type) {
167168
vma = find_vma(current->mm, user_address);
168169
if (IS_ENABLED(HAILO_SUPPORT_MMIO_DMA_MAPPING)) {
169170
if (NULL == vma) {
170171
dev_err(dev, "no vma for virt_addr/size = 0x%08lx/0x%08zx\n", user_address, size);
171172
ret = -EFAULT;
172-
goto cleanup;
173+
goto unlock_cleanup;
173174
}
174175
}
175176

@@ -179,7 +180,7 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
179180
ret = create_fd_from_vma(dev, vma);
180181
if (ret < 0) {
181182
dev_err(dev, "Failed creating fd from vma in given dmabuf\n");
182-
goto cleanup;
183+
goto unlock_cleanup;
183184
}
184185
// Override user address with fd to the dmabuf - like normal dmabuf flow
185186
user_address = ret;
@@ -212,7 +213,7 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
212213
ret = hailo_map_dmabuf(dev, user_address, direction, &sgt, &dmabuf_info);
213214
if (ret < 0) {
214215
dev_err(dev, "Failed mapping dmabuf\n");
215-
goto cleanup;
216+
goto unlock_cleanup;
216217
}
217218
// If created dmabuf fd from vma need to decrement refcount and release fd
218219
if (created_dmabuf_fd_from_vma) {
@@ -234,6 +235,8 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
234235
}
235236
}
236237

238+
mmap_read_unlock(current->mm);
239+
237240
kref_init(&mapped_buffer->kref);
238241
mapped_buffer->device = dev;
239242
mapped_buffer->user_address = user_address;
@@ -249,6 +252,8 @@ struct hailo_vdma_buffer *hailo_vdma_buffer_map(struct device *dev,
249252
clear_sg_table(&sgt);
250253
free_buffer_struct:
251254
kfree(mapped_buffer);
255+
unlock_cleanup:
256+
mmap_read_unlock(current->mm);
252257
cleanup:
253258
return ERR_PTR(ret);
254259
}

0 commit comments

Comments
 (0)