From 99ca0dbf9daa6d5ae32c7601133d7c39cccbef8a Mon Sep 17 00:00:00 2001 From: guohao15 Date: Wed, 9 Apr 2025 11:34:16 +0800 Subject: [PATCH] bugfix:the inode may have been removed by other core in SMP The inode may has been unlinked from the tree in other core, but it is not yet freed. Signed-off-by: guohao15 --- fs/mqueue/mq_unlink.c | 10 ++++++---- fs/semaphore/sem_unlink.c | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/mqueue/mq_unlink.c b/fs/mqueue/mq_unlink.c index a0a2a275b65..508231ee6f4 100644 --- a/fs/mqueue/mq_unlink.c +++ b/fs/mqueue/mq_unlink.c @@ -153,12 +153,14 @@ int file_mq_unlink(FAR const char *mq_name) ret = inode_remove(fullpath); - /* inode_remove() should always fail with -EBUSY because we hae a reference - * on the inode. -EBUSY means that the inode was, indeed, unlinked but - * thatis could not be freed because there are references. + /* The inode may has been unlinked from the tree in other core, + * but it is not yet freed. */ - DEBUGASSERT(ret >= 0 || ret == -EBUSY); + if (ret < 0 && ret != -EBUSY) + { + goto errout_with_lock; + } /* Now we do not release the reference count in the normal way (by calling * inode release. Rather, we call mq_inode_release(). mq_inode_release diff --git a/fs/semaphore/sem_unlink.c b/fs/semaphore/sem_unlink.c index fc0186e7f13..9fde96acc95 100644 --- a/fs/semaphore/sem_unlink.c +++ b/fs/semaphore/sem_unlink.c @@ -118,13 +118,14 @@ int nxsem_unlink(FAR const char *name) ret = inode_remove(fullpath); - /* inode_remove() should always fail with -EBUSY because we hae a reference - * on the inode. -EBUSY means that the inode was, indeed, unlinked but - * thatis could not be freed because there are references. + /* The inode may has been unlinked from the tree in other core, + * but it is not yet freed. */ - DEBUGASSERT(ret >= 0 || ret == -EBUSY); - UNUSED(ret); + if (ret < 0 && ret != -EBUSY) + { + goto errout_with_lock; + } /* Now we do not release the reference count in the normal way (by calling * inode release. Rather, we call sem_close(). sem_close will decrement