Patchwork [1/3] powerpc/spufs: Use correct return value for spu_handle_mm_fault

login
register
mail settings
Submitter Jeremy Kerr
Date Feb. 17, 2009, 12:44 a.m.
Message ID <1234831454.359250.975318533038.1.gpush@pingu>
Download mbox | patch
Permalink /patch/23235/
State Accepted
Headers show

Comments

Jeremy Kerr - Feb. 17, 2009, 12:44 a.m.
Currently, spu_handle_mm_fault disregards the 'ret' variable and always
returns -EFAULT on error.

This change refactos spu_handle_mm_fault a little, to return the
ret variable as appropriate. This allows us to combine the error and
sucess paths.

Also, remove the #if-0-ed IS_VALID_EA() check, it has never been
used.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

---
 arch/powerpc/platforms/cell/spu_fault.c |   48 ++++++++++++++------------------
 1 file changed, 22 insertions(+), 26 deletions(-)
Arnd Bergmann - Feb. 19, 2009, 3:47 p.m.
On Tuesday 17 February 2009, Jeremy Kerr wrote:
> Currently, spu_handle_mm_fault disregards the 'ret' variable and always
> returns -EFAULT on error.
> 
> This change refactos spu_handle_mm_fault a little, to return the
> ret variable as appropriate. This allows us to combine the error and
> sucess paths.
> 
> Also, remove the #if-0-ed IS_VALID_EA() check, it has never been
> used.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

Acked-by: Arnd Bergmann <arnd@arndb.de>

Patch

diff --git a/arch/powerpc/platforms/cell/spu_fault.c b/arch/powerpc/platforms/cell/spu_fault.c
index c8b1cd4..95d8dad 100644
--- a/arch/powerpc/platforms/cell/spu_fault.c
+++ b/arch/powerpc/platforms/cell/spu_fault.c
@@ -39,60 +39,56 @@  int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
 	unsigned long is_write;
 	int ret;
 
-#if 0
-	if (!IS_VALID_EA(ea)) {
+	if (mm == NULL)
 		return -EFAULT;
-	}
-#endif /* XXX */
-	if (mm == NULL) {
-		return -EFAULT;
-	}
-	if (mm->pgd == NULL) {
+
+	if (mm->pgd == NULL)
 		return -EFAULT;
-	}
 
 	down_read(&mm->mmap_sem);
+	ret = -EFAULT;
 	vma = find_vma(mm, ea);
 	if (!vma)
-		goto bad_area;
-	if (vma->vm_start <= ea)
-		goto good_area;
-	if (!(vma->vm_flags & VM_GROWSDOWN))
-		goto bad_area;
-	if (expand_stack(vma, ea))
-		goto bad_area;
-good_area:
+		goto out_unlock;
+
+	if (ea < vma->vm_start) {
+		if (!(vma->vm_flags & VM_GROWSDOWN))
+			goto out_unlock;
+		if (expand_stack(vma, ea))
+			goto out_unlock;
+	}
+
 	is_write = dsisr & MFC_DSISR_ACCESS_PUT;
 	if (is_write) {
 		if (!(vma->vm_flags & VM_WRITE))
-			goto bad_area;
+			goto out_unlock;
 	} else {
 		if (dsisr & MFC_DSISR_ACCESS_DENIED)
-			goto bad_area;
+			goto out_unlock;
 		if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
-			goto bad_area;
+			goto out_unlock;
 	}
+
 	ret = 0;
 	*flt = handle_mm_fault(mm, vma, ea, is_write);
 	if (unlikely(*flt & VM_FAULT_ERROR)) {
 		if (*flt & VM_FAULT_OOM) {
 			ret = -ENOMEM;
-			goto bad_area;
+			goto out_unlock;
 		} else if (*flt & VM_FAULT_SIGBUS) {
 			ret = -EFAULT;
-			goto bad_area;
+			goto out_unlock;
 		}
 		BUG();
 	}
+
 	if (*flt & VM_FAULT_MAJOR)
 		current->maj_flt++;
 	else
 		current->min_flt++;
-	up_read(&mm->mmap_sem);
-	return ret;
 
-bad_area:
+out_unlock:
 	up_read(&mm->mmap_sem);
-	return -EFAULT;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(spu_handle_mm_fault);