fs/event/open: fix the inode information update outside of lock

For re-enter case, the inode information may unlock with not filled,
and get by other user. that lead to the error behavior.
Especially SMP scene.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
buxiasen
2025-07-16 12:17:11 +08:00
committed by Xiang Xiao
parent 1794fbaa61
commit 9205c60f01
+29 -25
View File
@@ -149,6 +149,17 @@ int nxevent_open(FAR nxevent_t **event, FAR const char *name,
goto errout_with_search;
}
/* Allocate the event group structure (using the appropriate allocator
* for the group)
*/
nevent = group_malloc(NULL, sizeof(struct nevent_inode_s));
if (!nevent)
{
ret = -ENOMEM;
goto errout_with_search;
}
/* Create the event group. First we have to extract the additional
* parameters from the variable argument list.
* REVISIT: Mode parameter is not currently used.
@@ -165,38 +176,31 @@ int nxevent_open(FAR nxevent_t **event, FAR const char *name,
inode_lock();
ret = inode_reserve(fullpath, mode, &inode);
if (ret >= 0)
{
/* Link to the inode */
inode->u.i_nevent = nevent;
nevent->ne_inode = inode;
/* Initialize the inode */
INODE_SET_NAMEDEVENT(inode);
atomic_fetch_add(&inode->i_crefs, 1);
/* Initialize the event groups */
nxevent_init(&nevent->ne_event, events);
}
inode_unlock();
if (ret < 0)
{
group_free(NULL, nevent);
goto errout_with_search;
}
/* Allocate the event group structure (using the appropriate allocator
* for the group)
*/
nevent = group_malloc(NULL, sizeof(struct nevent_inode_s));
if (!nevent)
{
ret = -ENOMEM;
goto errout_with_inode;
}
/* Link to the inode */
inode->u.i_nevent = nevent;
nevent->ne_inode = inode;
/* Initialize the inode */
INODE_SET_NAMEDEVENT(inode);
atomic_fetch_add(&inode->i_crefs, 1);
/* Initialize the event groups */
nxevent_init(&nevent->ne_event, events);
/* Return a reference to the event groups */
*event = &nevent->ne_event;