From 9088616fb3c4e0d3ec4efb20378691066a218f9c Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 16 Mar 2015 16:14:02 -0400 Subject: arch: tile: fix null pointer dereference on pt_regs pointer Cppcheck reports the following issue: [arch/tile/kernel/stack.c:116]: (error) Possible null pointer dereference: p In this case, on reporting on an odd fault, p is set to NULL and immediately afterwords p is dereferenced iff !kbt->profile is false. Rather than doing this check just return NULL rather than falling through to the potential null pointer dereference (since the original intentional outcome would be to return NULL anyhow) for this odd fault case. Signed-off-by: Colin Ian King Signed-off-by: Chris Metcalf [tweaked lightly] --- arch/tile/kernel/stack.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'arch/tile/kernel/stack.c') diff --git a/arch/tile/kernel/stack.c b/arch/tile/kernel/stack.c index 7ff5afdbd3aa..c42dce50acd8 100644 --- a/arch/tile/kernel/stack.c +++ b/arch/tile/kernel/stack.c @@ -108,14 +108,15 @@ static struct pt_regs *valid_fault_handler(struct KBacktraceIterator* kbt) p->sp < PAGE_OFFSET && p->sp != 0) { if (kbt->verbose) pr_err(" <%s while in user mode>\n", fault); - } else if (kbt->verbose) { - pr_err(" (odd fault: pc %#lx, sp %#lx, ex1 %#lx?)\n", - p->pc, p->sp, p->ex1); - p = NULL; + } else { + if (kbt->verbose) + pr_err(" (odd fault: pc %#lx, sp %#lx, ex1 %#lx?)\n", + p->pc, p->sp, p->ex1); + return NULL; } - if (!kbt->profile || ((1ULL << p->faultnum) & QUEUED_INTERRUPTS) == 0) - return p; - return NULL; + if (kbt->profile && ((1ULL << p->faultnum) & QUEUED_INTERRUPTS) != 0) + return NULL; + return p; } /* Is the pc pointing to a sigreturn trampoline? */ -- cgit v1.2.3-59-g8ed1b