ANDROID: dma-heap: Refactor code to allow for future in-kernel users
Refactor the code to make in-kernel use a bit more clean. Signed-off-by: John Stultz <john.stultz@linaro.org> Change-Id: I909a36ea6f2351415decbd489fd71ea03b2c2171 Bug: 154341375
This commit is contained in:
+28
-16
@@ -50,10 +50,31 @@ static dev_t dma_heap_devt;
|
||||
static struct class *dma_heap_class;
|
||||
static DEFINE_XARRAY_ALLOC(dma_heap_minors);
|
||||
|
||||
static struct dma_heap *dma_heap_find(const char *name)
|
||||
{
|
||||
struct dma_heap *h;
|
||||
|
||||
mutex_lock(&heap_list_lock);
|
||||
list_for_each_entry(h, &heap_list, list) {
|
||||
if (!strcmp(h->name, name)) {
|
||||
kref_get(&h->refcount);
|
||||
mutex_unlock(&heap_list_lock);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&heap_list_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int 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;
|
||||
|
||||
if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS)
|
||||
return -EINVAL;
|
||||
/*
|
||||
* Allocations from all heaps have to begin
|
||||
* and end on page boundaries.
|
||||
@@ -91,12 +112,6 @@ static long dma_heap_ioctl_allocate(struct file *file, void *data)
|
||||
if (heap_allocation->fd)
|
||||
return -EINVAL;
|
||||
|
||||
if (heap_allocation->fd_flags & ~DMA_HEAP_VALID_FD_FLAGS)
|
||||
return -EINVAL;
|
||||
|
||||
if (heap_allocation->heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS)
|
||||
return -EINVAL;
|
||||
|
||||
fd = dma_heap_buffer_alloc(heap, heap_allocation->len,
|
||||
heap_allocation->fd_flags,
|
||||
heap_allocation->heap_flags);
|
||||
@@ -219,7 +234,7 @@ void dma_heap_put(struct dma_heap *h)
|
||||
|
||||
struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
|
||||
{
|
||||
struct dma_heap *heap, *h, *err_ret;
|
||||
struct dma_heap *heap, *err_ret;
|
||||
struct device *dev_ret;
|
||||
int ret;
|
||||
|
||||
@@ -234,16 +249,13 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
|
||||
}
|
||||
|
||||
/* check the name is unique */
|
||||
mutex_lock(&heap_list_lock);
|
||||
list_for_each_entry(h, &heap_list, list) {
|
||||
if (!strcmp(h->name, exp_info->name)) {
|
||||
mutex_unlock(&heap_list_lock);
|
||||
pr_err("dma_heap: Already registered heap named %s\n",
|
||||
exp_info->name);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
heap = dma_heap_find(exp_info->name);
|
||||
if (heap) {
|
||||
pr_err("dma_heap: Already registered heap named %s\n",
|
||||
exp_info->name);
|
||||
dma_heap_put(heap);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
mutex_unlock(&heap_list_lock);
|
||||
|
||||
heap = kzalloc(sizeof(*heap), GFP_KERNEL);
|
||||
if (!heap)
|
||||
|
||||
Reference in New Issue
Block a user