Skip to content

Commit

Permalink
msm: kgsl: Remove 'fd' dependency to get dma_buf handle
Browse files Browse the repository at this point in the history
Get the dma_buf handle directly from 'vm_file' after
doing necessary checks on the file.

Change-Id: Id5eec16588d64e4e28483b32bb52d4d3d9b86b99
Signed-off-by: ravnar <[email protected]>
Signed-off-by: Sanjay Yadav <[email protected]>
  • Loading branch information
ravnar authored and chrmhoffmann committed Nov 20, 2022
1 parent 3d6d2ed commit f0d4103
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions drivers/gpu/msm/kgsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2165,15 +2165,6 @@ static int kgsl_setup_anon_useraddr(struct kgsl_pagetable *pagetable,
return ret;
}

static int match_file(const void *p, struct file *file, unsigned int fd)
{
/*
* We must return fd + 1 because iterate_fd stops searching on
* non-zero return, but 0 is a valid fd.
*/
return (p == file) ? (fd + 1) : 0;
}

static void _setup_cache_mode(struct kgsl_mem_entry *entry,
struct vm_area_struct *vma)
{
Expand Down Expand Up @@ -2212,8 +2203,6 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device,
vma = find_vma(current->mm, hostptr);

if (vma && vma->vm_file) {
int fd;

ret = check_vma_flags(vma, entry->memdesc.flags);
if (ret) {
up_read(&current->mm->mmap_sem);
Expand All @@ -2229,10 +2218,13 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device,
return -EFAULT;
}

/* Look for the fd that matches this the vma file */
fd = iterate_fd(current->files, 0, match_file, vma->vm_file);
if (fd != 0)
dmabuf = dma_buf_get(fd - 1);
/*
* Take a refcount because dma_buf_put() decrements the
* refcount
*/
get_file(vma->vm_file);

dmabuf = vma->vm_file->private_data;
}

if (IS_ERR_OR_NULL(dmabuf)) {
Expand Down

0 comments on commit f0d4103

Please sign in to comment.