| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| From: John Stultz <john.stultz@linaro.org> |
| Date: Fri, 14 Aug 2020 22:42:09 +0000 |
| Subject: ANDROID: dma-heap: Rework allocation calls to return struct dma_buf |
| instead of fd |
| |
| While most uses will want to allocate a fd for a dmabuf, there |
| are some cases where it might be useful to have just a dma_buf structure. |
| |
| So refactor the heap allocaiton functions to return a struct dma_buf |
| and add a dma_heap_bufferfd_alloc() function to convert that return a fd. |
| |
| [CPNOTE: 06/07/21] Lee: Asked vendor for an update via the bug |
| |
| Signed-off-by: John Stultz <john.stultz@linaro.org> |
| Change-Id: Id6fd7e8471b9555a08bcdf8ca210feb589fa51c1 |
| Bug: 154341375 |
| --- |
| drivers/dma-buf/dma-heap.c | 37 +++++++++++++++++++++++++++---------- |
| 1 file changed, 27 insertions(+), 10 deletions(-) |
| |
| diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c |
| --- a/drivers/dma-buf/dma-heap.c |
| +++ b/drivers/dma-buf/dma-heap.c |
| @@ -67,24 +67,40 @@ static struct dma_heap *dma_heap_find(const char *name) |
| return NULL; |
| } |
| |
| -static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, |
| - unsigned int fd_flags, |
| - unsigned int heap_flags) |
| +void dma_heap_buffer_free(struct dma_buf *dmabuf) |
| +{ |
| + dma_buf_put(dmabuf); |
| +} |
| + |
| +struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, |
| + unsigned int fd_flags, |
| + unsigned int heap_flags) |
| { |
| if (fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) |
| - return -EINVAL; |
| + return ERR_PTR(-EINVAL); |
| |
| if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) |
| - return -EINVAL; |
| + return ERR_PTR(-EINVAL); |
| /* |
| * Allocations from all heaps have to begin |
| * and end on page boundaries. |
| */ |
| len = PAGE_ALIGN(len); |
| if (!len) |
| - return -EINVAL; |
| + return ERR_PTR(-EINVAL); |
| + |
| + return heap->ops->allocate(heap, len, fd_flags, heap_flags); |
| +} |
| + |
| +int dma_heap_bufferfd_alloc(struct dma_heap *heap, size_t len, |
| + unsigned int fd_flags, |
| + unsigned int heap_flags) |
| +{ |
| + struct dma_buf *dmabuf; |
| + int fd; |
| + |
| + dmabuf = dma_heap_buffer_alloc(heap, len, fd_flags, heap_flags); |
| |
| - dmabuf = heap->ops->allocate(heap, len, fd_flags, heap_flags); |
| if (IS_ERR(dmabuf)) |
| return PTR_ERR(dmabuf); |
| |
| @@ -94,6 +110,7 @@ static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, |
| /* just return, as put will call release and that will free */ |
| } |
| return fd; |
| + |
| } |
| |
| static int dma_heap_open(struct inode *inode, struct file *file) |
| @@ -122,9 +139,9 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data) |
| if (heap_allocation->fd) |
| return -EINVAL; |
| |
| - fd = dma_heap_buffer_alloc(heap, heap_allocation->len, |
| - heap_allocation->fd_flags, |
| - heap_allocation->heap_flags); |
| + fd = dma_heap_bufferfd_alloc(heap, heap_allocation->len, |
| + heap_allocation->fd_flags, |
| + heap_allocation->heap_flags); |
| if (fd < 0) |
| return fd; |
| |