* [PATCH] fsnotify: add error handling for kmem_cache_create
@ 2018-06-12 4:16 Zhouyang Jia
2018-06-12 5:32 ` Amir Goldstein
2018-06-12 14:49 ` Jan Kara
0 siblings, 2 replies; 3+ messages in thread
From: Zhouyang Jia @ 2018-06-12 4:16 UTC (permalink / raw)
Cc: Zhouyang Jia, Jan Kara, Amir Goldstein, linux-fsdevel, 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/notify/dnotify/dnotify.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index 63a1ca4..216b411 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -387,6 +387,9 @@ static int __init dnotify_init(void)
dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC);
dnotify_mark_cache = KMEM_CACHE(dnotify_mark, SLAB_PANIC);
+ if (!dnotify_struct_cache || !dnotify_mark_cache)
+ return -ENOMEM;
+
dnotify_group = fsnotify_alloc_group(&dnotify_fsnotify_ops);
if (IS_ERR(dnotify_group))
panic("unable to allocate fsnotify group for dnotify\n");
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fsnotify: add error handling for kmem_cache_create
2018-06-12 4:16 [PATCH] fsnotify: add error handling for kmem_cache_create Zhouyang Jia
@ 2018-06-12 5:32 ` Amir Goldstein
2018-06-12 14:49 ` Jan Kara
1 sibling, 0 replies; 3+ messages in thread
From: Amir Goldstein @ 2018-06-12 5:32 UTC (permalink / raw)
To: Zhouyang Jia; +Cc: Jan Kara, linux-fsdevel, linux-kernel
On Tue, Jun 12, 2018 at 7:16 AM, Zhouyang Jia <jiazhouyang09@gmail.com> 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.
>
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
> fs/notify/dnotify/dnotify.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
> index 63a1ca4..216b411 100644
> --- a/fs/notify/dnotify/dnotify.c
> +++ b/fs/notify/dnotify/dnotify.c
> @@ -387,6 +387,9 @@ static int __init dnotify_init(void)
> dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC);
> dnotify_mark_cache = KMEM_CACHE(dnotify_mark, SLAB_PANIC);
>
> + if (!dnotify_struct_cache || !dnotify_mark_cache)
> + return -ENOMEM;
> +
If only one failed need to free the other.
> dnotify_group = fsnotify_alloc_group(&dnotify_fsnotify_ops);
> if (IS_ERR(dnotify_group))
> panic("unable to allocate fsnotify group for dnotify\n");
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fsnotify: add error handling for kmem_cache_create
2018-06-12 4:16 [PATCH] fsnotify: add error handling for kmem_cache_create Zhouyang Jia
2018-06-12 5:32 ` Amir Goldstein
@ 2018-06-12 14:49 ` Jan Kara
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2018-06-12 14:49 UTC (permalink / raw)
To: Zhouyang Jia; +Cc: Jan Kara, Amir Goldstein, linux-fsdevel, linux-kernel
On Tue 12-06-18 12:16:04, 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.
>
> Signed-off-by: Zhouyang Jia <jiazhouyang09@gmail.com>
> ---
> fs/notify/dnotify/dnotify.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
> index 63a1ca4..216b411 100644
> --- a/fs/notify/dnotify/dnotify.c
> +++ b/fs/notify/dnotify/dnotify.c
> @@ -387,6 +387,9 @@ static int __init dnotify_init(void)
> dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC);
> dnotify_mark_cache = KMEM_CACHE(dnotify_mark, SLAB_PANIC);
>
> + if (!dnotify_struct_cache || !dnotify_mark_cache)
> + return -ENOMEM;
> +
Caches are allocated with SLAB_PANIC - i.e., we panic the system if caches
cannot be created. And that's intended since something is really wrong with
the system in that case. So this check is pointless.
Honza
> dnotify_group = fsnotify_alloc_group(&dnotify_fsnotify_ops);
> if (IS_ERR(dnotify_group))
> panic("unable to allocate fsnotify group for dnotify\n");
> --
> 2.7.4
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-06-12 14:49 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:16 [PATCH] fsnotify: add error handling for kmem_cache_create Zhouyang Jia
2018-06-12 5:32 ` Amir Goldstein
2018-06-12 14:49 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).