Return-Path: Received: from mail-pf0-f193.google.com ([209.85.192.193]:33643 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750811AbeFLEQK (ORCPT ); Tue, 12 Jun 2018 00:16:10 -0400 From: Zhouyang Jia Cc: Zhouyang Jia , Jan Kara , Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] fsnotify: add error handling for kmem_cache_create Date: Tue, 12 Jun 2018 12:16:04 +0800 Message-Id: <1528776964-39826-1-git-send-email-jiazhouyang09@gmail.com> To: unlisted-recipients:; (no To-header on input) Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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 --- 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