aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/sgi-gru/grufault.c
diff options
context:
space:
mode:
authorJack Steiner <steiner@sgi.com>2009-12-15 19:48:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-16 10:20:15 -0500
commite006043a4d2da52bba9fd9cb7e5a22e2951ff69b (patch)
tree21fcb2c1997b3070b54df12ec4102d2489deeecd /drivers/misc/sgi-gru/grufault.c
parent33f3648342dc40f8bd6383a5a1a91c22e06f6b77 (diff)
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 <steiner@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/misc/sgi-gru/grufault.c')
-rw-r--r--drivers/misc/sgi-gru/grufault.c21
1 files changed, 12 insertions, 9 deletions
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)
90{ 90{
91 struct mm_struct *mm = current->mm; 91 struct mm_struct *mm = current->mm;
92 struct vm_area_struct *vma; 92 struct vm_area_struct *vma;
93 struct gru_thread_state *gts = NULL; 93 struct gru_thread_state *gts = ERR_PTR(-EINVAL);
94 94
95 down_write(&mm->mmap_sem); 95 down_write(&mm->mmap_sem);
96 vma = gru_find_vma(vaddr); 96 vma = gru_find_vma(vaddr);
97 if (vma) 97 if (!vma)
98 gts = gru_alloc_thread_state(vma, TSID(vaddr, vma)); 98 goto err;
99 if (!IS_ERR(gts)) { 99
100 mutex_lock(&gts->ts_ctxlock); 100 gts = gru_alloc_thread_state(vma, TSID(vaddr, vma));
101 downgrade_write(&mm->mmap_sem); 101 if (IS_ERR(gts))
102 } else { 102 goto err;
103 up_write(&mm->mmap_sem); 103 mutex_lock(&gts->ts_ctxlock);
104 } 104 downgrade_write(&mm->mmap_sem);
105 return gts;
105 106
107err:
108 up_write(&mm->mmap_sem);
106 return gts; 109 return gts;
107} 110}
108 111