Skip to content

Commit

Permalink
gru: check for valid vma
Browse files Browse the repository at this point in the history
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 <steiner@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Jack Steiner authored and Linus Torvalds committed Dec 16, 2009
1 parent 33f3648 commit e006043
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions drivers/misc/sgi-gru/grufault.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&gts->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(&gts->ts_ctxlock);
downgrade_write(&mm->mmap_sem);
return gts;

err:
up_write(&mm->mmap_sem);
return gts;
}

Expand Down

0 comments on commit e006043

Please sign in to comment.