Merge branch 'topic/pcm-drain-nonblock' into for-linus
[pandora-kernel.git] / mm / nommu.c
index 28754c4..66e81e7 100644 (file)
@@ -919,6 +919,10 @@ static int validate_mmap_request(struct file *file,
                if (!file->f_op->read)
                        capabilities &= ~BDI_CAP_MAP_COPY;
 
+               /* The file shall have been opened with read permission. */
+               if (!(file->f_mode & FMODE_READ))
+                       return -EACCES;
+
                if (flags & MAP_SHARED) {
                        /* do checks for writing, appending and locking */
                        if ((prot & PROT_WRITE) &&
@@ -1348,6 +1352,7 @@ unsigned long do_mmap_pgoff(struct file *file,
        }
 
        vma->vm_region = region;
+       add_nommu_region(region);
 
        /* set up the mapping */
        if (file && vma->vm_flags & VM_SHARED)
@@ -1357,8 +1362,6 @@ unsigned long do_mmap_pgoff(struct file *file,
        if (ret < 0)
                goto error_put_region;
 
-       add_nommu_region(region);
-
        /* okay... we have a mapping; now we have to register it */
        result = vma->vm_start;