Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e6c9ab4 authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: kgsl: Use dma_buf_get() to get dma_buf structure"

parents 5ef4d2eb 86695e1d
Loading
Loading
Loading
Loading
+33 −8
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2008-2021, The Linux Foundation. All rights reserved.
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
 */

#include <uapi/linux/sched/types.h>
@@ -2677,6 +2677,15 @@ static int kgsl_setup_anon_useraddr(struct kgsl_pagetable *pagetable,
}

#ifdef CONFIG_DMA_SHARED_BUFFER
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)
{
@@ -2714,6 +2723,8 @@ 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);
@@ -2729,13 +2740,27 @@ static int kgsl_setup_dmabuf_useraddr(struct kgsl_device *device,
			return -EFAULT;
		}

		/* Look for the fd that matches this vma file */
		fd = iterate_fd(current->files, 0, match_file, vma->vm_file);
		if (fd) {
			dmabuf = dma_buf_get(fd - 1);
			if (IS_ERR(dmabuf)) {
				up_read(&current->mm->mmap_sem);
				return PTR_ERR(dmabuf);
			}
			/*
		 * Take a refcount because dma_buf_put() decrements the
		 * refcount
			 * It is possible that the fd obtained from iterate_fd
			 * was closed before passing the fd to dma_buf_get().
			 * Hence dmabuf returned by dma_buf_get() could be
			 * different from vma->vm_file->private_data. Return
			 * failure if this happens.
			 */
		get_file(vma->vm_file);

		dmabuf = vma->vm_file->private_data;
			if (dmabuf != vma->vm_file->private_data) {
				dma_buf_put(dmabuf);
				up_read(&current->mm->mmap_sem);
				return -EBADF;
			}
		}
	}

	if (IS_ERR_OR_NULL(dmabuf)) {