[PATCH] kernfs: use nofail allocation for global locks
From: Ruoyu Wang
Date: Mon Jun 08 2026 - 02:38:17 EST
kernfs_lock_init() allocates the global kernfs lock storage during init
and then calls kernfs_mutex_init(), which initializes mutexes through the
allocated pointer. A WARN_ON() does not stop execution, so allocation
failure would still dereference NULL.
The lock storage is required for kernfs to operate. Use a nofail
GFP_KERNEL allocation so the init path does not continue without the
required object.
Signed-off-by: Ruoyu Wang <ruoyuw560@xxxxxxxxx>
---
fs/kernfs/mount.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index 6e3217b6e4811..6cf8e71e5bd08 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -451,8 +451,8 @@ static void __init kernfs_mutex_init(void)
static void __init kernfs_lock_init(void)
{
- kernfs_locks = kmalloc_obj(struct kernfs_global_locks);
- WARN_ON(!kernfs_locks);
+ kernfs_locks = kmalloc_obj(struct kernfs_global_locks,
+ GFP_KERNEL | __GFP_NOFAIL);
kernfs_mutex_init();
}
--
2.51.0