From: Jack Steiner Date: Wed, 16 Dec 2009 00:48:10 +0000 (-0800) Subject: gru: check for valid vma X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e006043a4d2da52bba9fd9cb7e5a22e2951ff69b;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git gru: check for valid vma Fix bug caused by failure to allocate a GRU gts structure. The old code failed to handle the case where the vma was invalid. Signed-off-by: Jack Steiner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c index ada7df7e0968..7466234450f3 100644 --- a/drivers/misc/sgi-gru/grufault.c +++ b/drivers/misc/sgi-gru/grufault.c @@ -90,19 +90,22 @@ static struct gru_thread_state *gru_alloc_locked_gts(unsigned long vaddr) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma; - struct gru_thread_state *gts = NULL; + struct gru_thread_state *gts = ERR_PTR(-EINVAL); down_write(&mm->mmap_sem); vma = gru_find_vma(vaddr); - if (vma) - gts = gru_alloc_thread_state(vma, TSID(vaddr, vma)); - if (!IS_ERR(gts)) { - mutex_lock(>s->ts_ctxlock); - downgrade_write(&mm->mmap_sem); - } else { - up_write(&mm->mmap_sem); - } + if (!vma) + goto err; + + gts = gru_alloc_thread_state(vma, TSID(vaddr, vma)); + if (IS_ERR(gts)) + goto err; + mutex_lock(>s->ts_ctxlock); + downgrade_write(&mm->mmap_sem); + return gts; +err: + up_write(&mm->mmap_sem); return gts; }