Patch to fix madvise() syscall to return -EBADF on non-file mapped regions. Signed Off by: Suzuki K P --- mm/madvise.c 2005-07-01 16:08:26.000000000 +0530 +++ mm/madvise.c.new 2005-07-01 16:07:45.000000000 +0530 @@ -62,9 +62,6 @@ static long madvise_willneed(struct vm_a { struct file *file = vma->vm_file; - if (!file) - return -EBADF; - start = ((start - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; if (end > vma->vm_end) end = vma->vm_end; @@ -114,8 +111,12 @@ static long madvise_dontneed(struct vm_a static long madvise_vma(struct vm_area_struct * vma, unsigned long start, unsigned long end, int behavior) { + struct file* filp = vma->vm_file; long error = -EBADF; + if(!filp) + goto out; + switch (behavior) { case MADV_NORMAL: case MADV_SEQUENTIAL: @@ -136,6 +137,7 @@ static long madvise_vma(struct vm_area_s break; } +out: return error; }