Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4914757imm; Mon, 11 Jun 2018 22:38:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK+Kds//b9DzQONEqo9YVAjKPsSG59QrJWGS2OSVzoKi0bjj2nyekcFL3ppNwiiJ/zOD81S X-Received: by 2002:a63:3c4c:: with SMTP id i12-v6mr1894432pgn.309.1528781912212; Mon, 11 Jun 2018 22:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528781912; cv=none; d=google.com; s=arc-20160816; b=agrct4NsdenePJnp6WsQDmdPn/Ejoo1ccmide+JQHumrttB0VUAuDQSLd8a7vQtb/l BRt+tLX6DnvigX8aV+uiMmyuMXqvyHGnvzl2DNLFU5KTi88LSVdYvBXubzOBIiWwRQN7 fcWKeZl8gpCmQo7c+p8ajcBpJh/GbPL2++YjLThfJ5LSUg6Zp51P7QEboLYNhahy048B 7v2nuG2Fs+kBkAQJaQaLftp9/zzwPRqxFWrYbu/c2mNpXiZbFfgObK515+z9+XbpzSxd jAGacWKXLnGga27L1vrx40wggXCnfm3WfVxw+MmL68Ip4lW5EN31PANTGenx0GZP2pnZ aQsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=f1UKvr66Escybq5NeRGshx1FfsH9+fGZXqfNnU4A1fA=; b=mihEp+5sLg8ez7l97C5g6zfEbef0lc1nhXdYxqcNLlFe2R5FzchQd8JsqJOLvSgN5d xJ9vOUoVPkjhLjk3ZNgdsbZDW/50Ttf1oYriH968hnkYZ6sGDoecwWzfBpkH+SAWWvtm Wt2nmzA9WDh4kKxcPl9xynmeHOy7QWBBzGvtujQm6mZr9445dhyxz08pAPEDcQ5TRQEL Q9f28OdEmM7NRon8hemCQ9eWar1odS7WNAHD6a33VfYfC0uQQI+xWd/CQMAEGY+Itqfe hI3HGtdER9NpPi6WKq4wXR3bJDGkTm/n/Io0ASEijWUr3Q/NdqLsSDYgDvTsiQkQH2i/ f5Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WFYJuddY; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21-v6si90136pfh.33.2018.06.11.22.38.18; Mon, 11 Jun 2018 22:38:32 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WFYJuddY; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932941AbeFLFhx (ORCPT + 99 others); Tue, 12 Jun 2018 01:37:53 -0400 Received: from mail-yb0-f193.google.com ([209.85.213.193]:42607 "EHLO mail-yb0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932448AbeFLFhv (ORCPT ); Tue, 12 Jun 2018 01:37:51 -0400 Received: by mail-yb0-f193.google.com with SMTP id d123-v6so7505665ybh.9; Mon, 11 Jun 2018 22:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=f1UKvr66Escybq5NeRGshx1FfsH9+fGZXqfNnU4A1fA=; b=WFYJuddYhso9Yd9QLPVxsk41uZP6J6l260XMnko2XO8/N2nt57z9n+IzPzt5gNupmk MDdnyurEYq7TbDCBLPpjY+9f/69QTLCXSm9VIieI7FDy0uOFhHoBLUdVjEclQjbfN3zz w9QxlM6UC2m0ktOCzxC/4KdWhG4XP9phapgu/KQjilqqWXzytp05sMj7ifib5xqTXFfb 0pHgtLtmQnFWzXbpTy+AVFFwpc5N43lT53bvumV/usayX1n9LdtiDD+ZELCpttNMHJw1 jXkNwBpZ3A30Z5rLe6ZmzPkRT6lL2a6UZqEZhd3gFKXOzkTCF3//Ak7gzWAG1luvucgS 83pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=f1UKvr66Escybq5NeRGshx1FfsH9+fGZXqfNnU4A1fA=; b=aduvKoa7t9XWkzaXEBOvFaBBVEqfzaSWj2+5IitGbIj4cwIQiLEQ8F2PU/NYMatau5 hEvXWi2aFlGZmvnSVR8ibBcxtGCRPkIoqcYEB/nirvrN1De9SfabLGVn3CNrPCxXeIDK Vy70d9ZS3cGhtKmAN0hnracM+V2ty/rR3f2gwisXGs9j3dUM+ONpWZ9pgw3H34n61/3T +16c9kixPauEdNqs7xpWvNK4IGDpEacNYyi8hr+NPv3KFOaoigZgt9jKVAOHk1dgdx9h a4TOcQ/YPVASk0Qpld2FjPoCACLT6AEmj0fgrB1HlqFG3UMqkrfJkqJFezyQccp6i943 Ujyg== X-Gm-Message-State: APt69E0XhisXLlr5eKNNJXOFUH/vOD8qL8omiD9T1Y2S9uhm5x6jkkHu wNT9TkjpmB/X4yJ/8mNXv9sXb9cVdGGvizgjjQI= X-Received: by 2002:a25:9d86:: with SMTP id v6-v6mr887725ybp.252.1528781871309; Mon, 11 Jun 2018 22:37:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a81:79cf:0:0:0:0:0 with HTTP; Mon, 11 Jun 2018 22:37:50 -0700 (PDT) In-Reply-To: <1528777174-40045-1-git-send-email-jiazhouyang09@gmail.com> References: <1528777174-40045-1-git-send-email-jiazhouyang09@gmail.com> From: Amir Goldstein Date: Tue, 12 Jun 2018 08:37:50 +0300 Message-ID: Subject: Re: [PATCH] fanotify: add error handling for kmem_cache_create To: Zhouyang Jia Cc: Jan Kara , linux-fsdevel , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 12, 2018 at 7:19 AM, 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/fanotify/fanotify_user.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c > index ec4d8c5..e3fa861 100644 > --- a/fs/notify/fanotify/fanotify_user.c > +++ b/fs/notify/fanotify/fanotify_user.c > @@ -959,9 +959,14 @@ static int __init fanotify_user_setup(void) > { > fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC); > fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC); > + if (!fanotify_mark_cache || !fanotify_event_cachep) > + return -ENOMEM; If only one failed need to free the other. > + > if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) { > fanotify_perm_event_cachep = > KMEM_CACHE(fanotify_perm_event_info, SLAB_PANIC); > + if (!fanotify_perm_event_cachep) > + return -ENOMEM; here as well. best implement as goto fail > } > > return 0; fail: if (fanotify_mark_cache) kmem_cache_destroy(fanotify_mark_cache); ... return -ENOMEM; Thanks, Amir.