From 0ac21a911b06246fbb677ab60e1ca08d6312a1af Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Thu, 4 Jul 2024 17:45:49 +0800 Subject: [PATCH] fs_rammap:Check last fileseek restore fpos Summary: When restoring rammap fpos, we check the return value to avoid potential problems caused by no error return if the restore fails. Signed-off-by: chenrun1 --- fs/mmap/fs_rammap.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index d25458ff42..401eaa02af 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -78,7 +78,7 @@ static int msync_rammap(FAR struct mm_map_entry_s *entry, FAR void *start, fpos = file_seek(filep, entry->offset + offset, SEEK_SET); if (fpos < 0) { - ferr("ERRORL Seek to position %"PRIdOFF" failed\n", fpos); + ferr("ERROR: Seek to position %"PRIdOFF" failed\n", fpos); return fpos; } @@ -109,7 +109,15 @@ static int msync_rammap(FAR struct mm_map_entry_s *entry, FAR void *start, /* Restore file pos */ - file_seek(filep, opos, SEEK_SET); + fpos = file_seek(filep, opos, SEEK_SET); + if (fpos < 0) + { + /* Ensure that we finally seek back to the current file pos */ + + ferr("ERROR: Seek back to position %"PRIdOFF" failed\n", fpos); + return fpos; + } + return nwrite >= 0 ? 0 : nwrite; }