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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71091EB64DD for ; Fri, 28 Jul 2023 22:29:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbjG1W3V (ORCPT ); Fri, 28 Jul 2023 18:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229715AbjG1W3U (ORCPT ); Fri, 28 Jul 2023 18:29:20 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34882D7E for ; Fri, 28 Jul 2023 15:29:18 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686d8c8fc65so1998648b3a.0 for ; Fri, 28 Jul 2023 15:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690583358; x=1691188158; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8umto85lFOsMjOOJkbaCNVGW8Pn8sjRWz/5J34AL9mI=; b=RHkA8ShzyZ11Ac14ktRMDEVa5HTOf84/TpVv8bKhfRH5PDWGIlsqtuAnJ5SOpctMfP NR89D0QRJD7H59RmoOiGP23zT8siCPuh/aFJr0sDys+NK5td/07olKEHto0ZPgihvU4z 4w+3YILrfKHQE9WhV/H6Bk00+30LaI7xPgedU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690583358; x=1691188158; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8umto85lFOsMjOOJkbaCNVGW8Pn8sjRWz/5J34AL9mI=; b=eSrFrKgi9QWgZ09iXI9Fv0u09GibmO5NXWZuuvF7npv50sShAldJdaAp/yEPVXXDEc LBqHlqg6pZc7ljNl1EvEABFtMw5v5X58vbvoDWGrZ7oMJL89i/YVDEWySxWwwV8+IVaF Okxb4jSptldXGbxiJ/nO79tAiL7cvTTA8XtE/ceD/Y0vt7jng1X9lKgCukxoXP3ORiQy vdKbqZaVxUpU+jWQqjL3DJw/3i96+TQCK5uKsRVoMdmUFgMahAl16panWw2c+vi/VRC8 B2zdfTyBBN4CoCCcsKs2ejFhCLRMIdeeSC6+bh+kyvEgC/yPMwtd/1R5j89gp9Gm0N9g dT1A== X-Gm-Message-State: ABy/qLaOciRGFPxbO97OX1A1YBZEfLaqosscRx/AjecT+8TRZxbm0b/X 2igmkSzWzwnE6U3QrtjqMjjhlw== X-Google-Smtp-Source: APBJJlER1FAg4n/elG1kpOAL3M0WPLwKlU/yvj9/qMTrf+Zkic2J1OOG0h4sfGtKezJLJUCEPQXtww== X-Received: by 2002:a05:6a20:9383:b0:134:1d88:1d88 with SMTP id x3-20020a056a20938300b001341d881d88mr3221404pzh.58.1690583358354; Fri, 28 Jul 2023 15:29:18 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id y15-20020aa7804f000000b0066a4e561beesm3752873pfm.173.2023.07.28.15.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:29:17 -0700 (PDT) Date: Fri, 28 Jul 2023 15:29:17 -0700 From: Kees Cook To: James Seo Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , "James E.J. Bottomley" , "Martin K. Petersen" , "Gustavo A. R. Silva" , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 6/6] scsi: mpt3sas: Replace a dynamic allocation with a local variable Message-ID: <202307281528.086CF1D063@keescook> References: <20230725161331.27481-1-james@equiv.tech> <20230725161331.27481-7-james@equiv.tech> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230725161331.27481-7-james@equiv.tech> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org On Tue, Jul 25, 2023 at 09:13:31AM -0700, James Seo wrote: > This dynamic allocation can be replaced with a local variable. > > Signed-off-by: James Seo > --- > drivers/scsi/mpt3sas/mpt3sas_base.c | 19 +++++-------------- > 1 file changed, 5 insertions(+), 14 deletions(-) > > diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c > index cd6f36094159..a32a6fa728a7 100644 > --- a/drivers/scsi/mpt3sas/mpt3sas_base.c > +++ b/drivers/scsi/mpt3sas/mpt3sas_base.c > @@ -5361,10 +5361,9 @@ _base_update_diag_trigger_pages(struct MPT3SAS_ADAPTER *ioc) > static int _base_assign_fw_reported_qd(struct MPT3SAS_ADAPTER *ioc) > { > Mpi2ConfigReply_t mpi_reply; > - Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; > + Mpi2SasIOUnitPage1_t sas_iounit_pg1; > Mpi26PCIeIOUnitPage1_t pcie_iounit_pg1; > u16 depth; > - int sz; > int rc = 0; > > ioc->max_wideport_qd = MPT3SAS_SAS_QUEUE_DEPTH; > @@ -5374,28 +5373,21 @@ static int _base_assign_fw_reported_qd(struct MPT3SAS_ADAPTER *ioc) > if (!ioc->is_gen35_ioc) > goto out; > /* sas iounit page 1 */ > - sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData); > - sas_iounit_pg1 = kzalloc(sizeof(Mpi2SasIOUnitPage1_t), GFP_KERNEL); Hunh. So Mpi2SasIOUnitPage1_t is used without the flexarray at all? -Kees > - if (!sas_iounit_pg1) { > - pr_err("%s: failure at %s:%d/%s()!\n", > - ioc->name, __FILE__, __LINE__, __func__); > - return rc; > - } > rc = mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, > - sas_iounit_pg1, sz); > + &sas_iounit_pg1, sizeof(Mpi2SasIOUnitPage1_t)); > if (rc) { > pr_err("%s: failure at %s:%d/%s()!\n", > ioc->name, __FILE__, __LINE__, __func__); > goto out; > } > > - depth = le16_to_cpu(sas_iounit_pg1->SASWideMaxQueueDepth); > + depth = le16_to_cpu(sas_iounit_pg1.SASWideMaxQueueDepth); > ioc->max_wideport_qd = (depth ? depth : MPT3SAS_SAS_QUEUE_DEPTH); > > - depth = le16_to_cpu(sas_iounit_pg1->SASNarrowMaxQueueDepth); > + depth = le16_to_cpu(sas_iounit_pg1.SASNarrowMaxQueueDepth); > ioc->max_narrowport_qd = (depth ? depth : MPT3SAS_SAS_QUEUE_DEPTH); > > - depth = sas_iounit_pg1->SATAMaxQDepth; > + depth = sas_iounit_pg1.SATAMaxQDepth; > ioc->max_sata_qd = (depth ? depth : MPT3SAS_SATA_QUEUE_DEPTH); > > /* pcie iounit page 1 */ > @@ -5414,7 +5406,6 @@ static int _base_assign_fw_reported_qd(struct MPT3SAS_ADAPTER *ioc) > "MaxWidePortQD: 0x%x MaxNarrowPortQD: 0x%x MaxSataQD: 0x%x MaxNvmeQD: 0x%x\n", > ioc->max_wideport_qd, ioc->max_narrowport_qd, > ioc->max_sata_qd, ioc->max_nvme_qd)); > - kfree(sas_iounit_pg1); > return rc; > } > > -- > 2.39.2 > -- Kees Cook