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 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-12-16 13:21:37 +08:00 committed by Xiang Xiao
parent a307dc0608
commit ccf477710a

View file

@ -73,8 +73,9 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
irqstate_t flags; irqstate_t flags;
flags = spin_lock_irqsave(&list->fl_lock); flags = spin_lock_irqsave(&list->fl_lock);
filep = &list->fl_files[l1][l2]; filep = &list->fl_files[l1][l2];
spin_unlock_irqrestore(&list->fl_lock, flags);
#ifdef CONFIG_FS_REFCOUNT #ifdef CONFIG_FS_REFCOUNT
if (filep->f_inode != NULL) if (filep->f_inode != NULL)
{ {
@ -110,7 +111,6 @@ static FAR struct file *files_fget_by_index(FAR struct filelist *list,
} }
#endif #endif
spin_unlock_irqrestore(&list->fl_lock, flags);
return filep; return filep;
} }