From ccf477710a0d9f1f5c1642a39d68a69875d4b2a2 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Mon, 16 Dec 2024 13:21:37 +0800 Subject: [PATCH] fs: Move fl_lock to a more appropriate location. reason: The list->fl_files may be modified by files_extend. If it is being modified, there will be a race condition for fl_files[l1][l2]. Signed-off-by: hujun5 --- fs/inode/fs_files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index c830ba864e..4c2baefab4 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -73,8 +73,9 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list, irqstate_t flags; flags = spin_lock_irqsave(&list->fl_lock); - filep = &list->fl_files[l1][l2]; + spin_unlock_irqrestore(&list->fl_lock, flags); + #ifdef CONFIG_FS_REFCOUNT if (filep->f_inode != NULL) { @@ -110,7 +111,6 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list, } #endif - spin_unlock_irqrestore(&list->fl_lock, flags); return filep; }