aboutsummaryrefslogtreecommitdiffstats
path: root/mm/mremap.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/mremap.c')
-rw-r--r--mm/mremap.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/mm/mremap.c b/mm/mremap.c
index 2dc44b1cb1df..034e2d360652 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -345,25 +345,25 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
345 struct vm_area_struct *vma = find_vma(mm, addr); 345 struct vm_area_struct *vma = find_vma(mm, addr);
346 346
347 if (!vma || vma->vm_start > addr) 347 if (!vma || vma->vm_start > addr)
348 goto Efault; 348 return ERR_PTR(-EFAULT);
349 349
350 if (is_vm_hugetlb_page(vma)) 350 if (is_vm_hugetlb_page(vma))
351 goto Einval; 351 return ERR_PTR(-EINVAL);
352 352
353 /* We can't remap across vm area boundaries */ 353 /* We can't remap across vm area boundaries */
354 if (old_len > vma->vm_end - addr) 354 if (old_len > vma->vm_end - addr)
355 goto Efault; 355 return ERR_PTR(-EFAULT);
356 356
357 /* Need to be careful about a growing mapping */ 357 /* Need to be careful about a growing mapping */
358 if (new_len > old_len) { 358 if (new_len > old_len) {
359 unsigned long pgoff; 359 unsigned long pgoff;
360 360
361 if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP)) 361 if (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP))
362 goto Efault; 362 return ERR_PTR(-EFAULT);
363 pgoff = (addr - vma->vm_start) >> PAGE_SHIFT; 363 pgoff = (addr - vma->vm_start) >> PAGE_SHIFT;
364 pgoff += vma->vm_pgoff; 364 pgoff += vma->vm_pgoff;
365 if (pgoff + (new_len >> PAGE_SHIFT) < pgoff) 365 if (pgoff + (new_len >> PAGE_SHIFT) < pgoff)
366 goto Einval; 366 return ERR_PTR(-EINVAL);
367 } 367 }
368 368
369 if (vma->vm_flags & VM_LOCKED) { 369 if (vma->vm_flags & VM_LOCKED) {
@@ -372,29 +372,20 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
372 lock_limit = rlimit(RLIMIT_MEMLOCK); 372 lock_limit = rlimit(RLIMIT_MEMLOCK);
373 locked += new_len - old_len; 373 locked += new_len - old_len;
374 if (locked > lock_limit && !capable(CAP_IPC_LOCK)) 374 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
375 goto Eagain; 375 return ERR_PTR(-EAGAIN);
376 } 376 }
377 377
378 if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) 378 if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT))
379 goto Enomem; 379 return ERR_PTR(-ENOMEM);
380 380
381 if (vma->vm_flags & VM_ACCOUNT) { 381 if (vma->vm_flags & VM_ACCOUNT) {
382 unsigned long charged = (new_len - old_len) >> PAGE_SHIFT; 382 unsigned long charged = (new_len - old_len) >> PAGE_SHIFT;
383 if (security_vm_enough_memory_mm(mm, charged)) 383 if (security_vm_enough_memory_mm(mm, charged))
384 goto Efault; 384 return ERR_PTR(-ENOMEM);
385 *p = charged; 385 *p = charged;
386 } 386 }
387 387
388 return vma; 388 return vma;
389
390Efault: /* very odd choice for most of the cases, but... */
391 return ERR_PTR(-EFAULT);
392Einval:
393 return ERR_PTR(-EINVAL);
394Enomem:
395 return ERR_PTR(-ENOMEM);
396Eagain:
397 return ERR_PTR(-EAGAIN);
398} 389}
399 390
400static unsigned long mremap_to(unsigned long addr, unsigned long old_len, 391static unsigned long mremap_to(unsigned long addr, unsigned long old_len,