Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp438274rdb; Mon, 15 Jan 2024 02:07:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDtd0IJRYrgVV9KFALH99F4RjvzCddTJ9qOniSrRY5Rc74IJqti6I3z6GYbAziE0TpqG9f X-Received: by 2002:a05:6402:1d1c:b0:557:aa16:1e44 with SMTP id dg28-20020a0564021d1c00b00557aa161e44mr2349930edb.79.1705313250422; Mon, 15 Jan 2024 02:07:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705313250; cv=none; d=google.com; s=arc-20160816; b=MNnwdg8FyRalkbFsMHN0OfOBSWTHDTa0YW2KgKLDqGOz5IKXfXGNVt+Fxs+ZvIlZSi gip/AEfBwNWXSZNpM60OCI3ijvggP1aE+dU12OuXPuzQecWDkhjJ8TLhXj3xpt5D8SjB uylSUvjU6uL5nYoXDCd7D4TmIrryCDvr0D4D2Cc7fVPq3qimLRoRX/BRW81eOLCg42DD b0hTtmkTn/uVFvjkUZbC3jHCKuCWNwIxkgr/XStnSTJAcK0MKmpC/4L8yPDh2euSRu+Q kX1nPqYInF25pE1bFSinHZBajU9HfWEDiSUM2BS6EPyeDjfpvbAzVBgYkQS2aNPgVOOa JEnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=1GRtHh3l1fdgDKSeF6Tj0GdEUV+yk+vJzwucQD0Cyts=; fh=+GiQH5lk41eNKngoAxDFU6fUIslwm6e+MTHE+MVfuo8=; b=cbXuQHxMU3lBBjfhyOVP07kthNBNP0UH8UU+LpPySCX+F1kxEYrzmmK/J0a/CLtOA5 E2gE2At/CBe2A3weRh2j4UdifyyZyXSsk9yoZ0kWOZBDF39a6pCy7uk8D3xdrc6Hskdz 2ap4D4CvFLvVJPrpf+e4wsZNZpW0sSwSK8u1lqMXpwqtBt7iBuSHldxM6Ciq2lysQrrl zU0e/wqOY8opBjgxBIfFDWQQi95QF+48hTWKRCSHF/wc34cDdko4r144XF0Ez7kjaoqc xqhPqEBA60OTW3kBsjL3ZpCP3Lc1IlA8ouwhrmK7w7eIpldAs70vd1LW1/tmQ+wCzx0Z d6PQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25853-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v6-20020a509546000000b005533e54351asi3748618eda.452.2024.01.15.02.07.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:07:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25853-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-25853-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25853-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D5F001F2189E for ; Mon, 15 Jan 2024 10:07:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BC011E864; Mon, 15 Jan 2024 10:06:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF1732C68B; Mon, 15 Jan 2024 10:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B51F12F4; Mon, 15 Jan 2024 02:07:18 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.91.116]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EC7F43F6C4; Mon, 15 Jan 2024 02:06:30 -0800 (PST) Date: Mon, 15 Jan 2024 10:06:24 +0000 From: Mark Rutland To: Erick Archer Cc: Steven Rostedt , Masami Hiramatsu , "Gustavo A. R. Silva" , Mathieu Desnoyers , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] eventfs: Use kcalloc() instead of kzalloc() Message-ID: References: <20240114105340.5746-1-erick.archer@gmx.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240114105340.5746-1-erick.archer@gmx.com> On Sun, Jan 14, 2024 at 11:53:40AM +0100, Erick Archer wrote: > Use 2-factor multiplication argument form kcalloc() instead > of kzalloc(). > > Link: https://github.com/KSPP/linux/issues/162 > Signed-off-by: Erick Archer Could you put something in the commit message explaining *why* this change should be made? I assume that this is so that overflows during multiplication can be caught and handled in some way, but the commit message doesn't say that, and nor does the linked github page. The patch itself looks fine. Thanks, Mark. > --- > fs/tracefs/event_inode.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c > index fdff53d5a1f8..f8196289692c 100644 > --- a/fs/tracefs/event_inode.c > +++ b/fs/tracefs/event_inode.c > @@ -93,7 +93,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, > /* Preallocate the children mode array if necessary */ > if (!(dentry->d_inode->i_mode & S_IFDIR)) { > if (!ei->entry_attrs) { > - ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, > + ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs), > GFP_NOFS); > if (!ei->entry_attrs) { > ret = -ENOMEM; > @@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode > } > > if (size) { > - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); > + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); > if (!ei->d_children) { > kfree_const(ei->name); > kfree(ei); > @@ -941,7 +941,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry > goto fail; > > if (size) { > - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); > + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); > if (!ei->d_children) > goto fail; > } > -- > 2.25.1 > >