fs/mmap: update mapped var before exit

Signed-off-by: Xuxingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Xuxingliang
2023-01-16 18:03:58 +08:00
committed by Xiang Xiao
parent dce315005a
commit 9166eeddf6
2 changed files with 15 additions and 13 deletions
+9 -6
View File
@@ -102,7 +102,8 @@ static int file_mmap_(FAR struct file *filep, FAR void *start,
if ((flags & MAP_ANONYMOUS) != 0) if ((flags & MAP_ANONYMOUS) != 0)
{ {
return map_anonymous(&entry, kernel); ret = map_anonymous(&entry, kernel);
goto out;
} }
if (filep == NULL) 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) filep->f_inode->u.i_ops->mmap != NULL)
{ {
ret = filep->f_inode->u.i_ops->mmap(filep, &entry); ret = filep->f_inode->u.i_ops->mmap(filep, &entry);
if (ret == OK)
{
*mapped = entry.vaddr;
}
} }
else 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. * do much better in the KERNEL build using the MMU.
*/ */
return rammap(filep, &entry, kernel); ret = rammap(filep, &entry, kernel);
} }
/* Return */ /* Return */
out:
if (ret == OK)
{
*mapped = entry.vaddr;
}
return ret; return ret;
} }
+6 -7
View File
@@ -130,14 +130,13 @@ static int unmap_rammap(FAR struct task_group_s *group,
* *
* Input Parameters: * Input Parameters:
* filep file descriptor of the backing file -- required. * filep file descriptor of the backing file -- required.
* length The length of the mapping. For exception #1 above, this length * entry mmap entry information.
* ignored: The entire underlying media is always accessible. * field offset and length must be initialized correctly.
* offset The offset into the file to map
* kernel kmm_zalloc or kumm_zalloc * kernel kmm_zalloc or kumm_zalloc
* mapped The pointer to the mapped area
* *
* Returned Value: * 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 * EBADF
* 'fd' is not a valid file descriptor. * '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: errout_with_region:
if (kernel) if (kernel)
{ {
kmm_free(rdbuffer); kmm_free(entry->vaddr);
} }
else else
{ {
kumm_free(rdbuffer); kumm_free(entry->vaddr);
} }
return ret; return ret;