Skip to contentSkip to conversation

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

PATCH New Anton Blanchard 1 participant 1 message Apr 13, 2016 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

Fixes d740037fac70 ("sched/cpuacct: Split usage accounting into user_usage and sys_usage")

---

kernel/sched/cpuacct.c +3 -4
index df947e0..41f85c4 100644
@@ -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();