Skip to content

Commit 1bef400

Browse files
SuzukiLinus Torvalds
authored andcommitted
[PATCH] madvise: Avoid returning error code -EBADF for anonymous mappings
Revert this recent correctness change: Douglas Crosher <dcrosher@scieneer.com> reported that it broke an existing application, and that madvise() works without error on anonymous mappings on Solaris. This means that madvise() will remain non-standards-compliant: we should return -EBADF for all requests against non-file-backed vma's, but Linux only does this for MADV_WILLNEED requests. 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>
1 parent 22c1ea4 commit 1bef400

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

‎mm/madvise.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ static long madvise_willneed(struct vm_area_struct * vma,
8383
{
8484
struct file *file = vma->vm_file;
8585

86+
if (!file)
87+
return -EBADF;
88+
8689
if (file->f_mapping->a_ops->get_xip_page) {
8790
/* no bad return value, but ignore advice */
8891
return 0;
@@ -141,11 +144,7 @@ static long
141144
madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
142145
unsigned long start, unsigned long end, int behavior)
143146
{
144-
struct file *filp = vma->vm_file;
145-
long error = -EBADF;
146-
147-
if (!filp)
148-
goto out;
147+
long error;
149148

150149
switch (behavior) {
151150
case MADV_NORMAL:
@@ -166,8 +165,6 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
166165
error = -EINVAL;
167166
break;
168167
}
169-
170-
out:
171168
return error;
172169
}
173170

0 commit comments

Comments
 (0)