Add a dedicated function for handling errors. Signed-off-by: Riley Andrews <riandrews@xxxxxxxxxxx> --- drivers/android/binder.c | 51 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index c98436c..a3129d4 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -2593,6 +2593,35 @@ static int binder_wait_for_work(struct binder_thread *thread, int non_block, return ret; } +static int binder_handle_thread_error(struct binder_thread *thread, + void * __user *ptr, void __user *end) +{ + struct binder_proc *proc = thread->proc; + + if (*ptr == end) + return 0; + + if (thread->return_error2 != BR_OK) { + if (put_user(thread->return_error2, (uint32_t __user *)*ptr)) + return -EFAULT; + + *ptr += sizeof(uint32_t); + binder_stat_br(proc, thread, thread->return_error2); + thread->return_error2 = BR_OK; + + if (*ptr == end) + return 0; + } + + if (put_user(thread->return_error, (uint32_t __user *)*ptr)) + return -EFAULT; + + *ptr += sizeof(uint32_t); + binder_stat_br(proc, thread, thread->return_error); + thread->return_error = BR_OK; + return 0; +} + static int binder_thread_read(struct binder_proc *proc, struct binder_thread *thread, binder_uintptr_t binder_buffer, size_t size, @@ -2613,23 +2642,11 @@ static int binder_thread_read(struct binder_proc *proc, retry: wait_for_proc_work = thread->transaction_stack == NULL && - list_empty(&thread->todo); - - if (thread->return_error != BR_OK && ptr < end) { - if (thread->return_error2 != BR_OK) { - if (put_user(thread->return_error2, (uint32_t __user *)ptr)) - return -EFAULT; - ptr += sizeof(uint32_t); - binder_stat_br(proc, thread, thread->return_error2); - thread->return_error2 = BR_OK; - if (ptr == end) - goto done; - } - if (put_user(thread->return_error, (uint32_t __user *)ptr)) - return -EFAULT; - ptr += sizeof(uint32_t); - binder_stat_br(proc, thread, thread->return_error); - thread->return_error = BR_OK; + list_empty(&thread->todo); + if (thread->return_error != BR_OK) { + ret = binder_handle_thread_error(thread, &ptr, end); + if (ret < 0) + return ret; goto done; } -- 2.2.0.rc0.207.ga3a616c _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel