diff --git a/fs/mmap/fs_munmap.c b/fs/mmap/fs_munmap.c index 41f25a43b3..ac7daf8e6a 100644 --- a/fs/mmap/fs_munmap.c +++ b/fs/mmap/fs_munmap.c @@ -60,22 +60,27 @@ static int file_munmap_(FAR void *start, size_t length, bool kernel) ret = mm_map_lock(); if (ret == OK) { - while (ret == OK && (entry = mm_map_find(mm, start, length))) + entry = mm_map_find(mm, start, length); + + /* If entry don't find, the start and length is invalid. */ + + if (entry == NULL) + { + ret = -EINVAL; + goto unlock; + } + + do { DEBUGASSERT(entry->munmap); ret = entry->munmap(group, entry, start, length); } + while (ret == OK && (entry = mm_map_find(mm, start, length))); +unlock: mm_map_unlock(); } - /* If entry don't find, the start and length is invalid. */ - - if (entry == NULL) - { - return -EINVAL; - } - return ret; }