lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1432854511-33320-14-git-send-email-riandrews@android.com>
Date:	Thu, 28 May 2015 16:08:31 -0700
From:	Riley Andrews <riandrews@...roid.com>
To:	linux-kernel@...r.kernel.org,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Arve Hjønnevåg <arve@...roid.com>,
	Riley Andrews <riandrews@...roid.com>,
	devel@...verdev.osuosl.org
Subject: [PATCH 13/13] android: binder: add function for processing work nodes in binder_thread_read

Split up binder_thread_read into a function for waiting for work
and a function for processing the work nodes.

Signed-off-by: Riley Andrews <riandrews@...roid.com>
---
 drivers/android/binder.c | 96 ++++++++++++++++++++++++++++--------------------
 1 file changed, 56 insertions(+), 40 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index a3129d4..1ae8db7 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -2622,39 +2622,16 @@ static int binder_handle_thread_error(struct binder_thread *thread,
 	return 0;
 }
 
-static int binder_thread_read(struct binder_proc *proc,
-			      struct binder_thread *thread,
-			      binder_uintptr_t binder_buffer, size_t size,
-			      binder_size_t *consumed, int non_block)
+static int binder_thread_read_do_work(struct binder_thread *thread,
+				      bool wait_for_proc_work,
+				      void __user *buffer,
+				      void __user *end,
+				      void * __user *ptr)
 {
-	void __user *buffer = (void __user *)(uintptr_t)binder_buffer;
-	void __user *ptr = buffer + *consumed;
-	void __user *end = buffer + size;
-
-	int ret = 0;
-	int wait_for_proc_work;
-
-	if (*consumed == 0) {
-		if (put_user(BR_NOOP, (uint32_t __user *)ptr))
-			return -EFAULT;
-		ptr += sizeof(uint32_t);
-	}
-
-retry:
-	wait_for_proc_work = thread->transaction_stack == NULL &&
-			     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;
-	}
-
-	ret = binder_wait_for_work(thread, non_block, wait_for_proc_work);
-	if (ret)
-		return ret;
+	int ret;
+	struct binder_proc *proc = thread->proc;
 
-	while (((end - ptr) >= sizeof(struct binder_transaction_data) + 4)) {
+	while (((end - *ptr) >= sizeof(struct binder_transaction_data) + 4)) {
 		struct binder_work *w;
 		bool done_processing_work = false;
 
@@ -2665,16 +2642,12 @@ retry:
 			w = list_first_entry(&proc->todo, struct binder_work,
 					     entry);
 		} else {
-			/* no data added */
-			if (ptr - buffer == 4 &&
-			    !(thread->looper & BINDER_LOOPER_STATE_NEED_RETURN))
-				goto retry;
 			break;
 		}
 
 		switch (w->type) {
 		case BINDER_WORK_TRANSACTION:
-			ret = binder_work_transaction(thread, w, &ptr);
+			ret = binder_work_transaction(thread, w, ptr);
 			/*
 			 * Threads can only handle one incoming transaction,
 			 * at a time, so return before processing any more
@@ -2683,10 +2656,10 @@ retry:
 			done_processing_work = true;
 			break;
 		case BINDER_WORK_TRANSACTION_COMPLETE:
-			ret = binder_work_tr_complete(thread, w, &ptr);
+			ret = binder_work_tr_complete(thread, w, ptr);
 			break;
 		case BINDER_WORK_NODE:
-			ret = binder_work_node(thread, w, &ptr);
+			ret = binder_work_node(thread, w, ptr);
 			break;
 		case BINDER_WORK_DEAD_BINDER:
 		case BINDER_WORK_DEAD_BINDER_AND_CLEAR:
@@ -2697,7 +2670,7 @@ retry:
 			 */
 			done_processing_work = true;
 		case BINDER_WORK_CLEAR_DEATH_NOTIFICATION:
-			ret = binder_work_dead_binder(thread, w, &ptr);
+			ret = binder_work_dead_binder(thread, w, ptr);
 			break;
 		}
 		if (ret < 0)
@@ -2706,8 +2679,51 @@ retry:
 		if (done_processing_work)
 			break;
 	}
+	return 0;
+}
 
-done:
+static int binder_thread_read(struct binder_proc *proc,
+			      struct binder_thread *thread,
+			      binder_uintptr_t binder_buffer, size_t size,
+			      binder_size_t *consumed, int non_block)
+{
+	void __user *buffer = (void __user *)(uintptr_t)binder_buffer;
+	void __user *ptr = buffer + *consumed;
+	void __user *end = buffer + size;
+	bool wait_for_proc_work;
+
+	int ret = 0;
+
+	if (*consumed == 0) {
+		if (put_user(BR_NOOP, (uint32_t __user *)ptr))
+			return -EFAULT;
+		ptr += sizeof(uint32_t);
+	}
+
+	do {
+		if (thread->return_error != BR_OK) {
+			ret =  binder_handle_thread_error(thread, &ptr, end);
+			if (ret < 0)
+				return ret;
+			break;
+		}
+		if (!thread->transaction_stack && list_empty(&thread->todo))
+			wait_for_proc_work = true;
+		else
+			wait_for_proc_work = false;
+
+		ret = binder_wait_for_work(thread, non_block,
+					   wait_for_proc_work);
+		if (ret)
+			return ret;
+
+		ret = binder_thread_read_do_work(thread, wait_for_proc_work,
+						 buffer, end, &ptr);
+		if (ret)
+			return ret;
+	} while ((ptr - buffer == 4) &&
+		 !(thread->looper & BINDER_LOOPER_STATE_NEED_RETURN) &&
+		 ((end - ptr) >= sizeof(struct binder_transaction_data) + 4));
 
 	*consumed = ptr - buffer;
 	if (proc->requested_threads + proc->ready_threads == 0 &&
-- 
2.2.0.rc0.207.ga3a616c

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ