From 9d3c1f77da035dd8b413069fa7a3108623468ead Mon Sep 17 00:00:00 2001 From: Paul Capron Date: Wed, 28 Oct 2020 11:36:43 +0100 Subject: [PATCH] vfs: Fix counting in `inode_avail_count` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As seen in `inode_del` (and `inode_alloc`), a free (`NOT_INIT`) node can be found anywhere in `g_vfs_dev_nodes`; it’s a “sparse” list. So when checking for free nodes, the iterating index variable (`e`) shall be used, not the counter (`count`). The code got that wrong. For instance, if the first node is not available (type is not `VFS_TYPE_NOT_INIT`), then the function previously returned 0, no matter what, and was iterating the node list in vain. --- components/fs/vfs/src/vfs_inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/fs/vfs/src/vfs_inode.c b/components/fs/vfs/src/vfs_inode.c index ed2378d6..595c61b8 100644 --- a/components/fs/vfs/src/vfs_inode.c +++ b/components/fs/vfs/src/vfs_inode.c @@ -131,7 +131,7 @@ int inode_avail_count(void) int e = 0; for (; e < AOS_CONFIG_VFS_DEV_NODES; e++) { - if (g_vfs_dev_nodes[count].type == VFS_TYPE_NOT_INIT) { + if (g_vfs_dev_nodes[e].type == VFS_TYPE_NOT_INIT) { count++; } }