mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 14:27:37 +08:00
fs/close: move inode to last to void race condition
race condition:
A Thread: B Thread:
close
file_close
filep->inode = NULL
context switch
-------------------> open to alloc same fd
read from IO
filep->f_tag = 0 <-------------------
filep->f_san = 0 -------------------> ioctl(fd, ...)
fdcheck trigger assert
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
+4
-4
@@ -162,10 +162,6 @@ int file_close(FAR struct file *filep)
|
|||||||
ret = file_close_without_clear(filep);
|
ret = file_close_without_clear(filep);
|
||||||
if (ret >= 0 && filep->f_inode)
|
if (ret >= 0 && filep->f_inode)
|
||||||
{
|
{
|
||||||
/* Reset the user file struct instance so that it cannot be reused. */
|
|
||||||
|
|
||||||
filep->f_inode = NULL;
|
|
||||||
|
|
||||||
#ifdef CONFIG_FDCHECK
|
#ifdef CONFIG_FDCHECK
|
||||||
filep->f_tag_fdcheck = 0;
|
filep->f_tag_fdcheck = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -173,6 +169,10 @@ int file_close(FAR struct file *filep)
|
|||||||
#ifdef CONFIG_FDSAN
|
#ifdef CONFIG_FDSAN
|
||||||
filep->f_tag_fdsan = 0;
|
filep->f_tag_fdsan = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Reset the user file struct instance so that it cannot be reused. */
|
||||||
|
|
||||||
|
filep->f_inode = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user