This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9205c60f01612860f0f7433d7a13a5c2348c9da2 Author: buxiasen <[email protected]> AuthorDate: Wed Jul 16 12:17:11 2025 +0800 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 <[email protected]> --- fs/event/event_open.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/fs/event/event_open.c b/fs/event/event_open.c index a2457096b37..2f0b45f52b1 100644 --- a/fs/event/event_open.c +++ b/fs/event/event_open.c @@ -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,37 +176,30 @@ int nxevent_open(FAR nxevent_t **event, FAR const char *name, inode_lock(); ret = inode_reserve(fullpath, mode, &inode); - inode_unlock(); - - if (ret < 0) + if (ret >= 0) { - goto errout_with_search; - } + /* Link to the inode */ - /* 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; - } + inode->u.i_nevent = nevent; + nevent->ne_inode = inode; - /* Link to the inode */ + /* Initialize the inode */ - inode->u.i_nevent = nevent; - nevent->ne_inode = inode; + INODE_SET_NAMEDEVENT(inode); + atomic_fetch_add(&inode->i_crefs, 1); - /* Initialize the inode */ + /* Initialize the event groups */ - INODE_SET_NAMEDEVENT(inode); - atomic_fetch_add(&inode->i_crefs, 1); + nxevent_init(&nevent->ne_event, events); + } - /* Initialize the event groups */ + inode_unlock(); - nxevent_init(&nevent->ne_event, events); + if (ret < 0) + { + group_free(NULL, nevent); + goto errout_with_search; + } /* Return a reference to the event groups */
