Commit 78260ac6 authored by Tair Rzayev's avatar Tair Rzayev Committed by Greg Kroah-Hartman

staging: android: binder.c: binder_ioctl() cleanup

binder_ioctl() is quite huge and checkpatch dirty - mostly because of
the amount of code for the BINDER_WRITE_READ and BINDER_SET_CONTEXT_MGR.
Moved that code into the new binder_ioctl_write_read() and
binder_ioctl_set_ctx_mgr()
Signed-off-by: default avatarTair Rzayev <tair.rzayev@gmail.com>
Cc: Arve Hjønnevåg <arve@android.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent ddac7d5f
...@@ -2593,41 +2593,23 @@ static unsigned int binder_poll(struct file *filp, ...@@ -2593,41 +2593,23 @@ static unsigned int binder_poll(struct file *filp,
return 0; return 0;
} }
static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static int binder_ioctl_write_read(struct file *filp,
unsigned int cmd, unsigned long arg,
struct binder_thread *thread)
{ {
int ret; int ret = 0;
struct binder_proc *proc = filp->private_data; struct binder_proc *proc = filp->private_data;
struct binder_thread *thread;
unsigned int size = _IOC_SIZE(cmd); unsigned int size = _IOC_SIZE(cmd);
void __user *ubuf = (void __user *)arg; void __user *ubuf = (void __user *)arg;
kuid_t curr_euid = current_euid();
/*pr_info("binder_ioctl: %d:%d %x %lx\n", proc->pid, current->pid, cmd, arg);*/
trace_binder_ioctl(cmd, arg);
ret = wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
if (ret)
goto err_unlocked;
binder_lock(__func__);
thread = binder_get_thread(proc);
if (thread == NULL) {
ret = -ENOMEM;
goto err;
}
switch (cmd) {
case BINDER_WRITE_READ: {
struct binder_write_read bwr; struct binder_write_read bwr;
if (size != sizeof(struct binder_write_read)) { if (size != sizeof(struct binder_write_read)) {
ret = -EINVAL; ret = -EINVAL;
goto err; goto out;
} }
if (copy_from_user(&bwr, ubuf, sizeof(bwr))) { if (copy_from_user(&bwr, ubuf, sizeof(bwr))) {
ret = -EFAULT; ret = -EFAULT;
goto err; goto out;
} }
binder_debug(BINDER_DEBUG_READ_WRITE, binder_debug(BINDER_DEBUG_READ_WRITE,
"%d:%d write %lld at %016llx, read %lld at %016llx\n", "%d:%d write %lld at %016llx, read %lld at %016llx\n",
...@@ -2645,7 +2627,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -2645,7 +2627,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
bwr.read_consumed = 0; bwr.read_consumed = 0;
if (copy_to_user(ubuf, &bwr, sizeof(bwr))) if (copy_to_user(ubuf, &bwr, sizeof(bwr)))
ret = -EFAULT; ret = -EFAULT;
goto err; goto out;
} }
} }
if (bwr.read_size > 0) { if (bwr.read_size > 0) {
...@@ -2659,7 +2641,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -2659,7 +2641,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (ret < 0) { if (ret < 0) {
if (copy_to_user(ubuf, &bwr, sizeof(bwr))) if (copy_to_user(ubuf, &bwr, sizeof(bwr)))
ret = -EFAULT; ret = -EFAULT;
goto err; goto out;
} }
} }
binder_debug(BINDER_DEBUG_READ_WRITE, binder_debug(BINDER_DEBUG_READ_WRITE,
...@@ -2669,29 +2651,31 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -2669,29 +2651,31 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
(u64)bwr.read_consumed, (u64)bwr.read_size); (u64)bwr.read_consumed, (u64)bwr.read_size);
if (copy_to_user(ubuf, &bwr, sizeof(bwr))) { if (copy_to_user(ubuf, &bwr, sizeof(bwr))) {
ret = -EFAULT; ret = -EFAULT;
goto err; goto out;
} }
break; out:
} return ret;
case BINDER_SET_MAX_THREADS: }
if (copy_from_user(&proc->max_threads, ubuf, sizeof(proc->max_threads))) {
ret = -EINVAL; static int binder_ioctl_set_ctx_mgr(struct file *filp)
goto err; {
} int ret = 0;
break; struct binder_proc *proc = filp->private_data;
case BINDER_SET_CONTEXT_MGR: kuid_t curr_euid = current_euid();
if (binder_context_mgr_node != NULL) { if (binder_context_mgr_node != NULL) {
pr_err("BINDER_SET_CONTEXT_MGR already set\n"); pr_err("BINDER_SET_CONTEXT_MGR already set\n");
ret = -EBUSY; ret = -EBUSY;
goto err; goto out;
} }
if (uid_valid(binder_context_mgr_uid)) { if (uid_valid(binder_context_mgr_uid)) {
if (!uid_eq(binder_context_mgr_uid, curr_euid)) { if (!uid_eq(binder_context_mgr_uid, curr_euid)) {
pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n", pr_err("BINDER_SET_CONTEXT_MGR bad uid %d != %d\n",
from_kuid(&init_user_ns, curr_euid), from_kuid(&init_user_ns, curr_euid),
from_kuid(&init_user_ns, binder_context_mgr_uid)); from_kuid(&init_user_ns,
binder_context_mgr_uid));
ret = -EPERM; ret = -EPERM;
goto err; goto out;
} }
} else { } else {
binder_context_mgr_uid = curr_euid; binder_context_mgr_uid = curr_euid;
...@@ -2699,12 +2683,56 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -2699,12 +2683,56 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
binder_context_mgr_node = binder_new_node(proc, 0, 0); binder_context_mgr_node = binder_new_node(proc, 0, 0);
if (binder_context_mgr_node == NULL) { if (binder_context_mgr_node == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto out;
} }
binder_context_mgr_node->local_weak_refs++; binder_context_mgr_node->local_weak_refs++;
binder_context_mgr_node->local_strong_refs++; binder_context_mgr_node->local_strong_refs++;
binder_context_mgr_node->has_strong_ref = 1; binder_context_mgr_node->has_strong_ref = 1;
binder_context_mgr_node->has_weak_ref = 1; binder_context_mgr_node->has_weak_ref = 1;
out:
return ret;
}
static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int ret;
struct binder_proc *proc = filp->private_data;
struct binder_thread *thread;
unsigned int size = _IOC_SIZE(cmd);
void __user *ubuf = (void __user *)arg;
/*pr_info("binder_ioctl: %d:%d %x %lx\n",
proc->pid, current->pid, cmd, arg);*/
trace_binder_ioctl(cmd, arg);
ret = wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2);
if (ret)
goto err_unlocked;
binder_lock(__func__);
thread = binder_get_thread(proc);
if (thread == NULL) {
ret = -ENOMEM;
goto err;
}
switch (cmd) {
case BINDER_WRITE_READ:
ret = binder_ioctl_write_read(filp, cmd, arg, thread);
if (ret)
goto err;
break;
case BINDER_SET_MAX_THREADS:
if (copy_from_user(&proc->max_threads, ubuf, sizeof(proc->max_threads))) {
ret = -EINVAL;
goto err;
}
break;
case BINDER_SET_CONTEXT_MGR:
ret = binder_ioctl_set_ctx_mgr(filp);
if (ret)
goto err;
break; break;
case BINDER_THREAD_EXIT: case BINDER_THREAD_EXIT:
binder_debug(BINDER_DEBUG_THREADS, "%d:%d exit\n", binder_debug(BINDER_DEBUG_THREADS, "%d:%d exit\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment