Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5434748imm; Tue, 12 Jun 2018 07:49:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKW7d7S9HbXA4WRnbZ5wYuFH8WA0CzuS2PWaZKicrqN96dDvNoOJL8kShmj47m2tpJOIc+D X-Received: by 2002:a62:f615:: with SMTP id x21-v6mr718812pfh.43.1528814998301; Tue, 12 Jun 2018 07:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814998; cv=none; d=google.com; s=arc-20160816; b=rimPaKct60mEW5fKiEXHqFBjRTo9H1RNRh99ilIlOv2aUQlqxseW/CNxLPYHz9ZHR3 dQLp5R0vpVcW3mjkYQNVHkzK2XwYw8hyhnRAq2uCyO6Ba4jcCqkS7dF+n/6UJMyt948E M+6F89oRgUyA9sa2+T4FB2lhlCmaalNMgRNenYYtK1SlqnSwfCQeX87N6zL5jOUJuYJz MAyhBfr4mS4OQ6HP/U7bErvHYDuiok061qq9N1vPGf7ONrgSJChQvQYAVGWy2jHjD8r2 YNH918GE9mY55vnOI5NDnvX7hL61B96yuXIkK9TAtU5W2R4xlz5bWrNnVmG+K4oTMMWo gIDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=kgq/PkeTDqyQAVw5qomXJnmBqdFo4W8Ek6R5nu4U1Vo=; b=HYdHOSlngLPavrIYWJFG8E0VxdWus35/Ih5bIA7Q2LBqVE42/4o8PmZlDB+7SofCVm 2DxuCVjSM3DRFvG3susJKp9GHuSufS2h693+AXXEjNppWqXHWYy+ZXWFLKnSX1lYyIIp S/Y5ts5FFMMx4dacQJwIoPD3oUAoi1o1BCUofRCaOGzkf6xiWuhRvWabOPOyEn/KkdHb QDCkjcaE3cwImvukEx3bpmcFDcq/DqqycPxcleGchX8QYlBEEJByBSDqlAj76fCCVOX8 D6uTIKdO4e4szAwXuoNxLnmI4aR0Cq1WVT6+xwYnuLzpw5suEHpSk3RoIyNTzsDbIpmD ur5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9-v6si213763pgf.497.2018.06.12.07.49.42; Tue, 12 Jun 2018 07:49:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754352AbeFLOtT (ORCPT + 99 others); Tue, 12 Jun 2018 10:49:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:44811 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754257AbeFLOtS (ORCPT ); Tue, 12 Jun 2018 10:49:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EE9A2AC8A; Tue, 12 Jun 2018 14:49:16 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id BCEF01E0D63; Tue, 12 Jun 2018 16:49:16 +0200 (CEST) Date: Tue, 12 Jun 2018 16:49:16 +0200 From: Jan Kara To: Zhouyang Jia Cc: Jan Kara , Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fsnotify: add error handling for kmem_cache_create Message-ID: <20180612144916.5vuqy3v6nrtcxksh@quack2.suse.cz> References: <1528776964-39826-1-git-send-email-jiazhouyang09@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1528776964-39826-1-git-send-email-jiazhouyang09@gmail.com> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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 SUSE Labs, CR