[PATCH] proc: add error handling for kmem_cache_create
From: Zhouyang Jia
Date: Tue Jun 12 2018 - 00:24:04 EST
When kmem_cache_create fails, the lack of error-handling code may
cause unexpected results.
This patch adds error-handling code after calling kmem_cache_create.
Signed-off-by: Zhouyang Jia <jiazhouyang09@xxxxxxxxx>
---
fs/proc/inode.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 2cf3b74..5d8b2d1 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -104,6 +104,9 @@ void __init proc_init_kmemcache(void)
pde_opener_cache =
kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
SLAB_ACCOUNT|SLAB_PANIC, NULL);
+ if (!proc_inode_cachep || !pde_opener_cache)
+ return -ENOMEM;
+
proc_dir_entry_cache = kmem_cache_create_usercopy(
"proc_dir_entry", sizeof(struct proc_dir_entry), 0, SLAB_PANIC,
offsetof(struct proc_dir_entry, inline_name),
--
2.7.4