[tip:sched/core] sched/cpuacct: Check for NULL when using task_pt_regs()

From: tip-bot for Anton Blanchard
Date: Wed Apr 13 2016 - 07:52:37 EST


Commit-ID: bd92883051a0228cc34996b8e766111ba10c9aac
Gitweb: http://git.kernel.org/tip/bd92883051a0228cc34996b8e766111ba10c9aac
Author: Anton Blanchard <anton@xxxxxxxxx>
AuthorDate: Wed, 6 Apr 2016 21:59:50 +1000
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitDate: Wed, 13 Apr 2016 13:22:37 +0200

sched/cpuacct: Check for NULL when using task_pt_regs()

task_pt_regs() can return NULL for kernel threads, so add a check.
This fixes an oops at boot on ppc64.

Reported-and-Tested-by: Srikar Dronamraju <srikar@xxxxxxxxxxxxxxxxxx>
Tested-by: Zhao Lei <zhaolei@xxxxxxxxxxxxxx>
Signed-off-by: Anton Blanchard <anton@xxxxxxxxx>
Acked-by: Zhao Lei <zhaolei@xxxxxxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: efault@xxxxxx
Cc: htejun@xxxxxxxxx
Cc: linuxppc-dev@xxxxxxxxxxxxxxxx
Cc: tj@xxxxxxxxxx
Cc: yangds.fnst@xxxxxxxxxxxxxx
Link: http://lkml.kernel.org/r/20160406215950.04bc3f0b@kryten
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
---
kernel/sched/cpuacct.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
index df947e0..41f85c4 100644
--- a/kernel/sched/cpuacct.c
+++ b/kernel/sched/cpuacct.c
@@ -316,12 +316,11 @@ static struct cftype files[] = {
void cpuacct_charge(struct task_struct *tsk, u64 cputime)
{
struct cpuacct *ca;
- int index;
+ int index = CPUACCT_USAGE_SYSTEM;
+ struct pt_regs *regs = task_pt_regs(tsk);

- if (user_mode(task_pt_regs(tsk)))
+ if (regs && user_mode(regs))
index = CPUACCT_USAGE_USER;
- else
- index = CPUACCT_USAGE_SYSTEM;

rcu_read_lock();