From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0D8BC433F5 for ; Mon, 25 Oct 2021 21:02:03 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85C0F61073 for ; Mon, 25 Oct 2021 21:02:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 85C0F61073 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bUO4HNp2rVx/N8vvgHgxmc+292ygwTOHsN+V+Q2e1yc=; b=1tdolP5ARi602cDIbSDyxyVHr8 77od7hXEDrXpW/Ez2oaYdebvNwsVTqOHB/h+6b4d+JFYsFXxh2HRc4+QjjV24TXDuIxS7XLeANfu6 OJo+f+/19H1b8KigKew0qcMcRZV3XMc9K5XP+dZ9llnKyZV8Uay2qospqYiSNKVpdQoWnNErXvhJ4 aATvfe01IQ48MJX0IVeTpCH9r98qz6shZQXjhHnXtAyyQkJrJ8eM58Ln9ph1a1lr/NVbgHpQyc/l+ DWp3cSQmghVhmn+lrSk9Uysjb9AUuQ1uMI8xA8hMnkWboSADE3r+/ErOrYlKz0zTOVITr0yK93EWa UCejJrlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mf76D-0002Tf-M5; Mon, 25 Oct 2021 21:01:41 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mf74o-0002AZ-EQ for linux-nvme@lists.infradead.org; Mon, 25 Oct 2021 21:00:15 +0000 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211025_140014_556015_76959AAE X-CRM114-Status: GOOD ( 16.30 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.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 >