[Crash-utility] [PATCH 2/4] refactor task_to_pid

Greg Thelen gthelen at google.com
Fri Apr 6 15:15:02 UTC 2018


task_to_pid and task_to_context both scan the set of tasks.
Simplify the code by refactoring task_to_pid to use task_to_context.
No functional change.

Signed-off-by: Greg Thelen <gthelen at google.com>
---
 task.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/task.c b/task.c
index 51aa2a255326..82fa015805cb 100644
--- a/task.c
+++ b/task.c
@@ -4618,15 +4618,12 @@ pid_to_task(ulong pid)
 ulong
 task_to_pid(ulong task)
 {
-        int i;
         struct task_context *tc;
 
-        
-        tc = FIRST_CONTEXT();
-        for (i = 0; i < RUNNING_TASKS(); i++, tc++) 
-                if (tc->task == task)
-                        return(tc->pid);
-        
+	tc = task_to_context(task);
+	if (tc != NULL)
+		return tc->pid;
+
         return(NO_PID);
 }
 
-- 
2.17.0.484.g0c8726318c-goog




More information about the Crash-utility mailing list