Commit 165cd40235732644b1856a5ed5e158c9b93f6010

Authored by suzuki
Committed by Linus Torvalds
1 parent 4bfdf37830

[PATCH] madvise() does not always return -EBADF on non-file mapped area

The madvise() system call returns -EBADF for areas which does not map to
files, only for *behaviour* request MADV_WILLNEED.

According to man pages, madvise returns :

EBADF - the map exists, but the area maps something that isn't a file.

Fixes bug 2995.

Signed-off-by: Suzuki K P <suzuki@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 1 changed file with 8 additions and 5 deletions Side-by-side Diff

... ... @@ -83,9 +83,6 @@
83 83 {
84 84 struct file *file = vma->vm_file;
85 85  
86   - if (!file)
87   - return -EBADF;
88   -
89 86 if (file->f_mapping->a_ops->get_xip_page) {
90 87 /* no bad return value, but ignore advice */
91 88 return 0;
92 89  
93 90  
... ... @@ -140,11 +137,16 @@
140 137 return 0;
141 138 }
142 139  
143   -static long madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
144   - unsigned long start, unsigned long end, int behavior)
  140 +static long
  141 +madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
  142 + unsigned long start, unsigned long end, int behavior)
145 143 {
  144 + struct file *filp = vma->vm_file;
146 145 long error = -EBADF;
147 146  
  147 + if (!filp)
  148 + goto out;
  149 +
148 150 switch (behavior) {
149 151 case MADV_NORMAL:
150 152 case MADV_SEQUENTIAL:
... ... @@ -165,6 +167,7 @@
165 167 break;
166 168 }
167 169  
  170 +out:
168 171 return error;
169 172 }
170 173