* [PATCH] proc: add error handling for kmem_cache_create
@ 2018-06-12 4:23 Zhouyang Jia
2018-06-12 5:09 ` Alexey Dobriyan
2018-06-12 5:21 ` kbuild test robot
0 siblings, 2 replies; 3+ messages in thread
From: Zhouyang Jia @ 2018-06-12 4:23 UTC (permalink / raw)
Cc: Zhouyang Jia, Andrew Morton, Alexey Dobriyan, Al Viro,
Thomas Gleixner, Greg Kroah-Hartman, linux-kernel
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@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] proc: add error handling for kmem_cache_create
2018-06-12 4:23 [PATCH] proc: add error handling for kmem_cache_create Zhouyang Jia
@ 2018-06-12 5:09 ` Alexey Dobriyan
2018-06-12 5:21 ` kbuild test robot
1 sibling, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2018-06-12 5:09 UTC (permalink / raw)
To: Zhouyang Jia
Cc: Andrew Morton, Al Viro, Thomas Gleixner, Greg Kroah-Hartman,
linux-kernel
On Tue, Jun 12, 2018 at 12:23:52PM +0800, Zhouyang Jia wrote:
> 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.
> 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;
SLAB_PANIC was added to not worry about error handling.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] proc: add error handling for kmem_cache_create
2018-06-12 4:23 [PATCH] proc: add error handling for kmem_cache_create Zhouyang Jia
2018-06-12 5:09 ` Alexey Dobriyan
@ 2018-06-12 5:21 ` kbuild test robot
1 sibling, 0 replies; 3+ messages in thread
From: kbuild test robot @ 2018-06-12 5:21 UTC (permalink / raw)
To: linux-kernel-owner
Cc: kbuild-all, Zhouyang Jia, Andrew Morton, Alexey Dobriyan, Al Viro,
Thomas Gleixner, Greg Kroah-Hartman, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1940 bytes --]
Hi,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v4.17 next-20180608]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/linux-kernel-owner-vger-kernel-org/proc-add-error-handling-for-kmem_cache_create/20180612-122737
config: i386-randconfig-x012-201823 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All warnings (new ones prefixed by >>):
fs/proc/inode.c: In function 'proc_init_kmemcache':
>> fs/proc/inode.c:108:10: warning: 'return' with a value, in function returning void
return -ENOMEM;
^
fs/proc/inode.c:96:13: note: declared here
void __init proc_init_kmemcache(void)
^~~~~~~~~~~~~~~~~~~
vim +/return +108 fs/proc/inode.c
95
96 void __init proc_init_kmemcache(void)
97 {
98 proc_inode_cachep = kmem_cache_create("proc_inode_cache",
99 sizeof(struct proc_inode),
100 0, (SLAB_RECLAIM_ACCOUNT|
101 SLAB_MEM_SPREAD|SLAB_ACCOUNT|
102 SLAB_PANIC),
103 init_once);
104 pde_opener_cache =
105 kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
106 SLAB_ACCOUNT|SLAB_PANIC, NULL);
107 if (!proc_inode_cachep || !pde_opener_cache)
> 108 return -ENOMEM;
109
110 proc_dir_entry_cache = kmem_cache_create_usercopy(
111 "proc_dir_entry", sizeof(struct proc_dir_entry), 0, SLAB_PANIC,
112 offsetof(struct proc_dir_entry, inline_name),
113 sizeof_field(struct proc_dir_entry, inline_name), NULL);
114 }
115
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33159 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-12 5:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-12 4:23 [PATCH] proc: add error handling for kmem_cache_create Zhouyang Jia
2018-06-12 5:09 ` Alexey Dobriyan
2018-06-12 5:21 ` kbuild test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox