Skip to contentSkip to conversation

bcachefs: allocate inode by using alloc_inode_sb()

PATCH New Youling Tang 1 participant 1 message Jul 16, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: allocate inode by using alloc_inode_sb()

From: Youling Tang <[email protected]>

The inode allocation is supposed to use alloc_inode_sb(), so convert kmem_cache_alloc() to alloc_inode_sb().

It will also fix [1] to avoid the NULL pointer dereference BUG in list_lru_add() when CONFIG_MEMCG is enabled.

Links:
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Fixes 86d81ec5f5f0 ("bcachefs: Mark bch_inode_info as SLAB_ACCOUNT")
---
 fs/bcachefs/fs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/bcachefs/fs.c +2 -1
index f9c9a95d7d4c..34649ed2e3a1 100644
@@ -227,7 +227,8 @@ static struct inode *bch2_alloc_inode(struct super_block *sb)
 
 static struct bch_inode_info *__bch2_new_inode(struct bch_fs *c)
 {
-	struct bch_inode_info *inode = kmem_cache_alloc(bch2_inode_cache, GFP_NOFS);
+	struct bch_inode_info *inode = alloc_inode_sb(c->vfs_sb,
+						bch2_inode_cache, GFP_NOFS);
 	if (!inode)
 		return NULL;
 
Signature · 1 line
2.34.1