This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 2305897c434 fs/tmpfs: check read EOF with the file locked
2305897c434 is described below

commit 2305897c434ba32a1999af0cdc285f01c5c6838f
Author: jingfei <[email protected]>
AuthorDate: Fri Nov 27 21:29:45 2026 +0800

    fs/tmpfs: check read EOF with the file locked
    
    Serialize the read EOF decision with the file size protected by the file 
lock. Reuse the existing unlock path for reads past EOF while preserving the 
strict size comparison and current atime behavior.
    
    Signed-off-by: jingfei <[email protected]>
---
 fs/tmpfs/fs_tmpfs.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c
index c3a5d082a55..63cb51b0fe5 100644
--- a/fs/tmpfs/fs_tmpfs.c
+++ b/fs/tmpfs/fs_tmpfs.c
@@ -2018,13 +2018,6 @@ static ssize_t tmpfs_readv(FAR struct file *filep, FAR 
struct uio *uio)
 
   tfo = filep->f_priv;
 
-  /* Directly return when the f_pos bigger then tfo_size */
-
-  if (filep->f_pos > tfo->tfo_size)
-    {
-      return 0;
-    }
-
   /* Get exclusive access to the file */
 
   ret = tmpfs_lock_file(tfo);
@@ -2033,6 +2026,14 @@ static ssize_t tmpfs_readv(FAR struct file *filep, FAR 
struct uio *uio)
       return ret;
     }
 
+  /* The file size can change while waiting for its lock. */
+
+  if (filep->f_pos > tfo->tfo_size)
+    {
+      nread = 0;
+      goto out;
+    }
+
   /* Handle attempts to read beyond the end of the file. */
 
   startpos = filep->f_pos;
@@ -2064,6 +2065,7 @@ static ssize_t tmpfs_readv(FAR struct file *filep, FAR 
struct uio *uio)
 
   /* Release the lock on the file */
 
+out:
   tmpfs_unlock_file(tfo);
   return nread;
 }

Reply via email to