summaryrefslogtreecommitdiff
path: root/drivers/staging/android/ion/ion.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/android/ion/ion.c')
-rwxr-xr-x[-rw-r--r--]drivers/staging/android/ion/ion.c81
1 files changed, 54 insertions, 27 deletions
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index f4fa3c9fc09f..80b045c2dc84 100644..100755
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -445,13 +445,22 @@ static void ion_handle_get(struct ion_handle *handle)
kref_get(&handle->ref);
}
-static int ion_handle_put(struct ion_handle *handle)
+static int ion_handle_put_nolock(struct ion_handle *handle)
+{
+ int ret;
+
+ ret = kref_put(&handle->ref, ion_handle_destroy);
+
+ return ret;
+}
+
+int ion_handle_put(struct ion_handle *handle)
{
struct ion_client *client = handle->client;
int ret;
mutex_lock(&client->lock);
- ret = kref_put(&handle->ref, ion_handle_destroy);
+ ret = ion_handle_put_nolock(handle);
mutex_unlock(&client->lock);
return ret;
@@ -475,20 +484,30 @@ static struct ion_handle *ion_handle_lookup(struct ion_client *client,
return ERR_PTR(-EINVAL);
}
-static struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
+static struct ion_handle *ion_handle_get_by_id_nolock(struct ion_client *client,
int id)
{
struct ion_handle *handle;
- mutex_lock(&client->lock);
handle = idr_find(&client->idr, id);
if (handle)
ion_handle_get(handle);
- mutex_unlock(&client->lock);
return handle ? handle : ERR_PTR(-EINVAL);
}
+struct ion_handle *ion_handle_get_by_id(struct ion_client *client,
+ int id)
+{
+ struct ion_handle *handle;
+
+ mutex_lock(&client->lock);
+ handle = ion_handle_get_by_id_nolock(client, id);
+ mutex_unlock(&client->lock);
+
+ return handle;
+}
+
static bool ion_handle_validate(struct ion_client *client,
struct ion_handle *handle)
{
@@ -614,26 +633,30 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
}
EXPORT_SYMBOL(ion_alloc);
-void __ion_free(struct ion_client *client, struct ion_handle *handle, int from_kern)
+static void __ion_free_nolock(struct ion_client *client, struct ion_handle *handle, int from_kern)
{
bool valid_handle;
BUG_ON(client != handle->client);
- mutex_lock(&client->lock);
valid_handle = ion_handle_validate(client, handle);
if (!valid_handle) {
WARN(1, "%s: invalid handle passed to free.\n", __func__);
- mutex_unlock(&client->lock);
return;
}
- mutex_unlock(&client->lock);
-
- if(from_kern)
+ if (from_kern)
ion_debug_kern_rec(client, handle->buffer, NULL, ION_FUNCTION_FREE, 0, 0, 0, 0);
+ ion_handle_put_nolock(handle);
+}
+
+static void __ion_free(struct ion_client *client, struct ion_handle *handle, int from_kern)
+{
+ BUG_ON(client != handle->client);
- ion_handle_put(handle);
+ mutex_lock(&client->lock);
+ __ion_free_nolock(client, handle, from_kern);
+ mutex_unlock(&client->lock);
}
void ion_free(struct ion_client *client, struct ion_handle *handle)
@@ -822,7 +845,7 @@ static int ion_debug_client_show(struct seq_file *s, void *unused)
names[id] = buffer->heap->name;
sizes[id] += buffer->size;
- seq_printf(s, "%16.s %3d %8zu %3d %p %p\n", buffer->heap->name,
+ seq_printf(s, "%16.s %3d %8zu %3d %pK %pK\n", buffer->heap->name,
client->pid, buffer->size, buffer->handle_count, handle, buffer);
}
mutex_unlock(&client->lock);
@@ -988,7 +1011,7 @@ void __ion_client_destroy(struct ion_client *client, int from_kern)
struct ion_handle *handle = rb_entry(n, struct ion_handle,
node);
mutex_lock(&client->lock);
- IONMSG("warning: release handle @ client destory: handle=%p, buf=%p, ref=%d, size=%ld, kmap=%d\n",
+ IONMSG("warning: release handle @ client destory: handle=%pK, buf=%pK, ref=%d, size=%ld, kmap=%d\n",
handle, handle->buffer, handle->buffer->ref, handle->buffer->size, handle->buffer->kmap_cnt);
ion_handle_destroy(&handle->ref);
mutex_unlock(&client->lock);
@@ -1145,7 +1168,7 @@ static void ion_vm_open(struct vm_area_struct *vma)
mutex_lock(&buffer->lock);
list_add(&vma_list->list, &buffer->vmas);
mutex_unlock(&buffer->lock);
- pr_debug("%s: adding %p\n", __func__, vma);
+ pr_debug("%s: adding %pK\n", __func__, vma);
}
static void ion_vm_close(struct vm_area_struct *vma)
@@ -1160,7 +1183,7 @@ static void ion_vm_close(struct vm_area_struct *vma)
continue;
list_del(&vma_list->list);
kfree(vma_list);
- pr_debug("%s: deleting %p\n", __func__, vma);
+ pr_debug("%s: deleting %pK\n", __func__, vma);
break;
}
mutex_unlock(&buffer->lock);
@@ -1341,7 +1364,7 @@ struct ion_handle *__ion_import_dma_buf(struct ion_client *client, int fd, int f
dmabuf = dma_buf_get(fd);
if (IS_ERR(dmabuf))
{
- IONMSG("ion_import: dma_buf_get fail fd=%d ret=0x%p\n", fd, dmabuf);
+ IONMSG("ion_import: dma_buf_get fail fd=%d ret=0x%pK\n", fd, dmabuf);
return ERR_PTR(PTR_ERR(dmabuf));
}
/* if this memory came from ion */
@@ -1479,11 +1502,15 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
struct ion_handle *handle;
- handle = ion_handle_get_by_id(client, data.handle.handle);
- if (IS_ERR(handle))
+ mutex_lock(&client->lock);
+ handle = ion_handle_get_by_id_nolock(client, data.handle.handle);
+ if (IS_ERR(handle)) {
+ mutex_unlock(&client->lock);
return PTR_ERR(handle);
- __ion_free(client, handle, 0);
- ion_handle_put(handle);
+ }
+ __ion_free_nolock(client, handle, 0);
+ ion_handle_put_nolock(handle);
+ mutex_unlock(&client->lock);
break;
}
case ION_IOC_SHARE:
@@ -1616,10 +1643,10 @@ static int ion_debug_heap_show(struct seq_file *s, void *unused)
char task_comm[TASK_COMM_LEN];
get_task_comm(task_comm, client->task);
- seq_printf(s, "%16.s(%16.s) %16u %16zu 0x%p\n", task_comm,
+ seq_printf(s, "%16.s(%16.s) %16u %16zu 0x%pK\n", task_comm,
client->dbg_name, client->pid, size, client);
} else {
- seq_printf(s, "%16.s(%16.s) %16u %16zu 0x%p\n", client->name,
+ seq_printf(s, "%16.s(%16.s) %16u %16zu 0x%pK\n", client->name,
"from_kernel", client->pid, size, client);
}
}
@@ -2270,7 +2297,7 @@ static int ion_debug_dbcl_show(struct seq_file *s, void *unused)
buffer_count++;
if(buffer_count == 1)
{
- seq_printf(s, "%8s[%2d] buffer: 0x%p buffer structure adr: 0x%p size(%d)\n", "buffer", buffer_cnt++, buf_rec->buffer, buf_rec->buffer_address, buf_rec->buffer->size);
+ seq_printf(s, "%8s[%2d] buffer: 0x%pK buffer structure adr: 0x%pK size(%d)\n", "buffer", buffer_cnt++, buf_rec->buffer, buf_rec->buffer_address, buf_rec->buffer->size);
}
seq_printf(s, "%s\n"," <BUFFER_ALLOCATION_LIST>");
seq_printf(s, "%s [0x%x] %10s [%d] (%s [%d])\n"," client",
@@ -2580,7 +2607,7 @@ static int ion_debug_dbis_show(struct seq_file *s, void *unused)
/* All clients */
for (cn = rb_first(&dev->clients); cn; cn = rb_next(cn)) {
client = rb_entry(cn, struct ion_client, node);
- seq_printf(s, "\n%8s[%2d] 0x%p PID[%d]\n", "client", client_cnt++, client, client->pid);
+ seq_printf(s, "\n%8s[%2d] 0x%pK PID[%d]\n", "client", client_cnt++, client, client->pid);
mutex_lock(&client->lock);
/* All client-handles */
for (hn = rb_first(&client->handles); hn; hn = rb_next(hn)) {
@@ -2601,7 +2628,7 @@ static int ion_debug_dbis_show(struct seq_file *s, void *unused)
client_cnt = 0;
while(client_rec != NULL)
{
- seq_printf(s, "\n[%2d]%s: fd[%d] 0x%p PID[%d] GROUP_PID[%d]\n",client_cnt++,"client",client_rec->fd, client_rec->tracking_info.recordID.client,client_rec->tracking_info.recordID.pid,client_rec->tracking_info.recordID.group_pid);
+ seq_printf(s, "\n[%2d]%s: fd[%d] 0x%pK PID[%d] GROUP_PID[%d]\n",client_cnt++,"client",client_rec->fd, client_rec->tracking_info.recordID.client,client_rec->tracking_info.recordID.pid,client_rec->tracking_info.recordID.group_pid);
/* Show buffer allocation backtrace */
seq_printf(s, " %s\n","<CLIENT_ALLOCATION_LIST>");
ion_debugdb_show_backtrace(s, &client_rec->tracking_info,ALLOCATE_BACKTRACE_INFO);
@@ -2624,7 +2651,7 @@ static int ion_debug_dbis_show(struct seq_file *s, void *unused)
#endif
while (buf_rec != NULL)
{
- seq_printf(s, "%8s[%2d][0x%x] buffer structure: 0x%p size(%d)\n", "buffer", buffer_cnt++,(unsigned int)buf_rec->buffer,buf_rec->buffer_address, buf_rec->buffer->size);
+ seq_printf(s, "%8s[%2d][0x%x] buffer structure: 0x%pK size(%d)\n", "buffer", buffer_cnt++,(unsigned int)buf_rec->buffer,buf_rec->buffer_address, buf_rec->buffer->size);
/* Allocation */
usg_rec = ion_get_list(LIST_BUFFER,buf_rec, BUFFER_ALLOCATION_LIST);
if(usg_rec)