Skip to content

Commit e3104f5

Browse files
cfd-36Linus Torvalds
authored andcommitted
[PATCH] uml: clean up after MADVISE_REMOVE
The MADVISE_REMOVE-checking code didn't clean up after itself. Signed-off-by: Jeff Dike <[email protected]> Cc: Paolo 'Blaisorblade' Giarrusso <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 191ef96 commit e3104f5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

arch/um/os-Linux/process.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,29 +206,36 @@ int os_drop_memory(void *addr, int length)
206206
int can_drop_memory(void)
207207
{
208208
void *addr;
209-
int fd;
209+
int fd, ok = 0;
210210

211211
printk("Checking host MADV_REMOVE support...");
212212
fd = create_mem_file(UM_KERN_PAGE_SIZE);
213213
if(fd < 0){
214214
printk("Creating test memory file failed, err = %d\n", -fd);
215-
return 0;
215+
goto out;
216216
}
217217

218218
addr = mmap64(NULL, UM_KERN_PAGE_SIZE, PROT_READ | PROT_WRITE,
219219
MAP_SHARED, fd, 0);
220220
if(addr == MAP_FAILED){
221221
printk("Mapping test memory file failed, err = %d\n", -errno);
222-
return 0;
222+
goto out_close;
223223
}
224224

225225
if(madvise(addr, UM_KERN_PAGE_SIZE, MADV_REMOVE) != 0){
226226
printk("MADV_REMOVE failed, err = %d\n", -errno);
227-
return 0;
227+
goto out_unmap;
228228
}
229229

230230
printk("OK\n");
231-
return 1;
231+
ok = 1;
232+
233+
out_unmap:
234+
munmap(addr, UM_KERN_PAGE_SIZE);
235+
out_close:
236+
close(fd);
237+
out:
238+
return ok;
232239
}
233240

234241
void init_new_thread_stack(void *sig_stack, void (*usr1_handler)(int))

0 commit comments

Comments
 (0)