From 9166eeddf6a7befe97783b43c80ac81446020d6b Mon Sep 17 00:00:00 2001 From: Xuxingliang Date: Mon, 16 Jan 2023 18:03:58 +0800 Subject: [PATCH] fs/mmap: update mapped var before exit Signed-off-by: Xuxingliang --- fs/mmap/fs_mmap.c | 15 +++++++++------ fs/mmap/fs_rammap.c | 13 ++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/mmap/fs_mmap.c b/fs/mmap/fs_mmap.c index 8d7a3f6d2a2..17505bd289d 100644 --- a/fs/mmap/fs_mmap.c +++ b/fs/mmap/fs_mmap.c @@ -102,7 +102,8 @@ static int file_mmap_(FAR struct file *filep, FAR void *start, if ((flags & MAP_ANONYMOUS) != 0) { - return map_anonymous(&entry, kernel); + ret = map_anonymous(&entry, kernel); + goto out; } if (filep == NULL) @@ -131,10 +132,6 @@ static int file_mmap_(FAR struct file *filep, FAR void *start, filep->f_inode->u.i_ops->mmap != NULL) { ret = filep->f_inode->u.i_ops->mmap(filep, &entry); - if (ret == OK) - { - *mapped = entry.vaddr; - } } else { @@ -146,11 +143,17 @@ static int file_mmap_(FAR struct file *filep, FAR void *start, * do much better in the KERNEL build using the MMU. */ - return rammap(filep, &entry, kernel); + ret = rammap(filep, &entry, kernel); } /* Return */ +out: + if (ret == OK) + { + *mapped = entry.vaddr; + } + return ret; } diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index 8eb6ca428ea..f497a0b71ba 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -130,14 +130,13 @@ static int unmap_rammap(FAR struct task_group_s *group, * * Input Parameters: * filep file descriptor of the backing file -- required. - * length The length of the mapping. For exception #1 above, this length - * ignored: The entire underlying media is always accessible. - * offset The offset into the file to map + * entry mmap entry information. + * field offset and length must be initialized correctly. * kernel kmm_zalloc or kumm_zalloc - * mapped The pointer to the mapped area * * Returned Value: - * On success, rammmap returns 0. Otherwise errno is returned appropriately. + * On success, rammap returns 0 and entry->vaddr points to memory mapped. + * Otherwise errno is returned appropriately. * * EBADF * 'fd' is not a valid file descriptor. @@ -251,11 +250,11 @@ int rammap(FAR struct file *filep, FAR struct mm_map_entry_s *entry, errout_with_region: if (kernel) { - kmm_free(rdbuffer); + kmm_free(entry->vaddr); } else { - kumm_free(rdbuffer); + kumm_free(entry->vaddr); } return ret;