Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4280e312 authored by David Howells's avatar David Howells Committed by Linus Torvalds
Browse files

frv: fix mmap2 error handling



Fix the error handling in sys_mmap2().  Currently, if the pgoff check
fails, fput() might have to be called (which it isn't), so do the pgoff
check first, before fget() is called.

Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reported-by: default avatarJulia Lawall <julia@diku.dk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a8005992
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -35,13 +35,6 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
	int error = -EBADF;
	struct file * file = NULL;

	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
	if (!(flags & MAP_ANONYMOUS)) {
		file = fget(fd);
		if (!file)
			goto out;
	}

	/* As with sparc32, make sure the shift for mmap2 is constant
	   (12), no matter what PAGE_SIZE we have.... */

@@ -49,8 +42,14 @@ asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
	   trying to map something we can't */
	if (pgoff & ((1 << (PAGE_SHIFT - 12)) - 1))
		return -EINVAL;
	pgoff >>= PAGE_SHIFT - 12;

	pgoff >>= (PAGE_SHIFT - 12);
	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
	if (!(flags & MAP_ANONYMOUS)) {
		file = fget(fd);
		if (!file)
			goto out;
	}

	down_write(&current->mm->mmap_sem);
	error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);