inotify: add error handling for kmem_cache_create
diff mbox

Message ID 1528777362-40212-1-git-send-email-jiazhouyang09@gmail.com
State New
Headers show

Commit Message

Zhouyang Jia June 12, 2018, 4:22 a.m. UTC
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/notify/inotify/inotify_user.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Chengguang Xu June 12, 2018, 7:41 a.m. UTC | #1
> 在 2018年6月12日,下午12:22,Zhouyang Jia <jiazhouyang09@gmail.com> 写道:
> 
> 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.

I think SLAB_PANIC can handle this case.

Thanks,
Chengguang.

> 
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
> fs/notify/inotify/inotify_user.c | 2 ++
> 1 file changed, 2 insertions(+)
> 
> diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
> index ef32f36..0704bab 100644
> --- a/fs/notify/inotify/inotify_user.c
> +++ b/fs/notify/inotify/inotify_user.c
> @@ -805,6 +805,8 @@ static int __init inotify_user_setup(void)
> 	BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
> 
> 	inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
> +	if (!inotify_inode_mark_cachep)
> +		return -ENOMEM;
> 
> 	inotify_max_queued_events = 16384;
> 	init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;
> -- 
> 2.7.4
>
Kassey Lee June 12, 2018, 9:53 a.m. UTC | #2
in __kmem_cache_create->kmem_cache_open

with SLAB_PANIC, kernel will panic if it fail

On Tue, Jun 12, 2018 at 3:41 PM, cgxu519@gmx.com <cgxu519@gmx.com> wrote:
>
>> 在 2018年6月12日,下午12:22,Zhouyang Jia <jiazhouyang09@gmail.com> 写道:
>>
>> 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.
>
> I think SLAB_PANIC can handle this case.
>
> Thanks,
> Chengguang.
>
>>
>> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
>> ---
>> fs/notify/inotify/inotify_user.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
>> index ef32f36..0704bab 100644
>> --- a/fs/notify/inotify/inotify_user.c
>> +++ b/fs/notify/inotify/inotify_user.c
>> @@ -805,6 +805,8 @@ static int __init inotify_user_setup(void)
>>       BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
>>
>>       inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
>> +     if (!inotify_inode_mark_cachep)
>> +             return -ENOMEM;
>>
>>       inotify_max_queued_events = 16384;
>>       init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;
>> --
>> 2.7.4
>>
>

Patch
diff mbox

diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index ef32f36..0704bab 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -805,6 +805,8 @@  static int __init inotify_user_setup(void)
 	BUG_ON(hweight32(ALL_INOTIFY_BITS) != 21);
 
 	inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);
+	if (!inotify_inode_mark_cachep)
+		return -ENOMEM;
 
 	inotify_max_queued_events = 16384;
 	init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;