fs/inode: Fix inoderemove when removing an inode without parent

This modification ensures that inoderemove will error instead of
trying to remove an inode without parent.

This fix was implement by Richard Jiayang Liu.

Signed-off-by: Richard Jiayang Liu <rjliu3@illinois.edu>
This commit is contained in:
Alan Carvalho de Assis
2025-05-24 12:59:52 -03:00
committed by Xiang Xiao
parent 6bcb8965cf
commit f113d13cbf

View File

@@ -92,7 +92,16 @@ static FAR struct inode *inode_unlink(FAR const char *path)
else
{
DEBUGASSERT(desc.parent != NULL);
/* The parent could be null if we are trying to remove the
* root inode. In that case, fail because we cannot remove it.
*/
if (desc.parent == NULL)
{
inode = NULL;
goto errout;
}
desc.parent->i_child = inode->i_peer;
}
@@ -101,6 +110,7 @@ static FAR struct inode *inode_unlink(FAR const char *path)
atomic_fetch_sub(&inode->i_crefs, 1);
}
errout:
RELEASE_SEARCH(&desc);
return inode;
}