Commit e3104f50 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

[PATCH] uml: clean up after MADVISE_REMOVE

The MADVISE_REMOVE-checking code didn't clean up after itself.
Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 191ef966
...@@ -206,29 +206,36 @@ int os_drop_memory(void *addr, int length) ...@@ -206,29 +206,36 @@ int os_drop_memory(void *addr, int length)
int can_drop_memory(void) int can_drop_memory(void)
{ {
void *addr; void *addr;
int fd; int fd, ok = 0;
printk("Checking host MADV_REMOVE support..."); printk("Checking host MADV_REMOVE support...");
fd = create_mem_file(UM_KERN_PAGE_SIZE); fd = create_mem_file(UM_KERN_PAGE_SIZE);
if(fd < 0){ if(fd < 0){
printk("Creating test memory file failed, err = %d\n", -fd); printk("Creating test memory file failed, err = %d\n", -fd);
return 0; goto out;
} }
addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE, addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0); MAP_SHARED, fd, 0);
if(addr == MAP_FAILED){ if(addr == MAP_FAILED){
printk("Mapping test memory file failed, err = %d\n", -errno); printk("Mapping test memory file failed, err = %d\n", -errno);
return 0; goto out_close;
} }
if(madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0){ if(madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0){
printk("MADV_REMOVE failed, err = %d\n", -errno); printk("MADV_REMOVE failed, err = %d\n", -errno);
return 0; goto out_unmap;
} }
printk("OK\n"); printk("OK\n");
return 1; ok = 1;
out_unmap:
munmap(addr, UM_KERN_PAGE_SIZE);
out_close:
close(fd);
out:
return ok;
} }
void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int)) void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment