Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp571452pxb; Mon, 25 Oct 2021 14:02:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkM4oLdTPyVeZKRiA6iqV0QJTbSE8G9TRXnIK0ZHcAbY58BwoklpAIXTjWtfm0EqSaF2N8 X-Received: by 2002:a17:90a:174a:: with SMTP id 10mr1630017pjm.31.1635195726321; Mon, 25 Oct 2021 14:02:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635195726; cv=none; d=google.com; s=arc-20160816; b=xCdM43juqyY6mojyu8J4oZfwM7wNrRTbKZs2y9I5jcIDsAGBfSxMuABsLX5BpjM3si XOgtAVfMmNys2Ljswof2iA8yZer5aa1WGa0s2bltM2oG7zrikMr5kjPiH56SlX8QGwsI Apz49z7WQmCyKNvGkTbzgeMZSwJoh6prGHy1Bs81KHWkgItxg9nS/kWq8LKq1q1OBgVq Ij2DjUeKCFjnmFxcx1Hm4j42zB3/5MkchtZZeqttt7mPlK46reUEK02vXOPKCkOmx4K9 lnOJI895rc3VPF9cJlEsW4t0AJ44l4+3vVUR8zC/CX6h4TFlHNZ/APXdfTJjq+Vb/zgW V7PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bUO4HNp2rVx/N8vvgHgxmc+292ygwTOHsN+V+Q2e1yc=; b=IhCKODGu/l0hAIDm7/+Bksfevj6yMQamYLfxcbYDMn0gW3dtafycn2aZh5CxOe56S5 qSTblSnUxa4IkExzZrrsoR+sykxi+uSM6d8qE508TYFAoFgZ+uP13QC5Ibkh4uNBsLoN eGd9qN45ivyGnF3BCUCIhp5WV4lCRDJ6nUNDrVMJ14/2VynrKsO5fzxtLe1i6v/KVEJ/ adKNX94B/Z8bs1Oo/tHJ6sc6+0tbFCcUwdFtL2NWOnasNwtdhKJGaZkQjA6L/+GISysj BnIvaYggBIBw+taWXFCKJ+7TXKtSlMGWmK5Cy6MmY48hdxr3hiw60d7Qc0OO0B2qzyRF qnvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s23QMnt9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rm12si20839950pjb.48.2021.10.25.14.01.52; Mon, 25 Oct 2021 14:02:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s23QMnt9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234187AbhJYVCm (ORCPT + 99 others); Mon, 25 Oct 2021 17:02:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:37204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbhJYVCf (ORCPT ); Mon, 25 Oct 2021 17:02:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8FE3961073; Mon, 25 Oct 2021 21:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635195612; bh=ZyMliUqV47n8vJU6KxKqCmYFPqznH//sZgzNbYo7fRM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s23QMnt9wl/QSimJBd4IO2681Yl0aMOOywtpMlgtJ8dEv/Udi6W+mtFYRfwSRwaG6 7IwW5sLh2mMRKlbKw2wBcBHmRGEHusnRNE+b/F/alR84XEs4G/PZ0D35HLAKFguzOb LaEyeW3UTEBSnVYAJqIMf3OjBlgs4bs61wFLdBaDTzi9VKOYfo43iBv9+1jAL8BSCB Y8yyB9GaKlsJ3scxWbHJv0lQ+V627i2l7t48sSw6gIkiYihIzOcGkHiJLzydXPPNLX bYsudmxKNwbHAKrPHcPwn6xyxcomLqmxoW6PkFzvH845Otn01aqDhNsSuyrqfrwZIl JZrhBxQCGGQAw== Date: Mon, 25 Oct 2021 16:05:03 -0500 From: "Gustavo A. R. Silva" To: Len Baker Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Kees Cook , linux-hardening@vger.kernel.org, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nvmet: prefer flex_array_size and struct_size over open coded arithmetic Message-ID: <20211025210503.GA1437674@embeddedor> References: <20211024172921.4110-1-len.baker@gmx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211024172921.4110-1-len.baker@gmx.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 24, 2021 at 07:29:21PM +0200, Len Baker wrote: > In an effort to avoid open-coded arithmetic in the kernel [1], use the > flex_array_size() and struct_size() helpers instead of an open-coded > calculation. > > [1] https://github.com/KSPP/linux/issues/160 > > Signed-off-by: Len Baker Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/nvme/host/multipath.c | 2 +- > drivers/nvme/target/admin-cmd.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c > index 954e84df6eb7..7f2071f2460c 100644 > --- a/drivers/nvme/host/multipath.c > +++ b/drivers/nvme/host/multipath.c > @@ -562,7 +562,7 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data, > return -EINVAL; > > nr_nsids = le32_to_cpu(desc->nnsids); > - nsid_buf_size = nr_nsids * sizeof(__le32); > + nsid_buf_size = flex_array_size(desc, nsids, nr_nsids); > > if (WARN_ON_ONCE(desc->grpid == 0)) > return -EINVAL; > diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c > index 403de678fd06..6fb24746de06 100644 > --- a/drivers/nvme/target/admin-cmd.c > +++ b/drivers/nvme/target/admin-cmd.c > @@ -264,7 +264,7 @@ static u32 nvmet_format_ana_group(struct nvmet_req *req, u32 grpid, > desc->chgcnt = cpu_to_le64(nvmet_ana_chgcnt); > desc->state = req->port->ana_state[grpid]; > memset(desc->rsvd17, 0, sizeof(desc->rsvd17)); > - return sizeof(struct nvme_ana_group_desc) + count * sizeof(__le32); > + return struct_size(desc, nsids, count); > } > > static void nvmet_execute_get_log_page_ana(struct nvmet_req *req) > -- > 2.25.1 >