Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2049225pxb; Mon, 8 Mar 2021 12:43:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjMZ0Sz4f95KWsiobMJBhI7mld7WL/Lf94JuOhp8yza22Au3Zqq8W9C4h6NL0hlIawBhYC X-Received: by 2002:aa7:c74a:: with SMTP id c10mr418852eds.332.1615236195739; Mon, 08 Mar 2021 12:43:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615236195; cv=none; d=google.com; s=arc-20160816; b=T3HRLLFTDjrROLlnB2K93XrVNDW/zxfy0WHLXp9YbNaexUVxne8GBW2fT5H65Zy35D jGRbIR495vo7H9JevFIV1E71kfHRcGCwrJTNc7klGDHVgVIthgsxNvTzboFaYdjmKhvi /TS8I+7Y2OvkbTNTmIwmWb7RoPEwtge388Gkm+HVS15D7L7UjwsiKGZni83NhAHFYGIE C13tgYGBBKzu4kgfZBsoUrj7zNq+uL4XrajFUmqvfRxhFKikI9QlCYbgkFdDYBnJWrZe 3rY4ToMbawjU6sY9Vkg86pUG1uOZmqCv4jh6qecK+GU2IwnjHUWQjxalW32WKG05qZr+ eTRw== 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=6IPC2d+kX/seqFLqXbNXPjNKMe5B/B5gGza8XjtZy1k=; b=ShVzng/nQWA4NiRbTHUc6qmL34ihRXfi32of3jQKTjbP5q3NSjmgGjVkWC9zymfzaX BCIinzsRYsYrHqm3rYXoev37Rg2K3qBIMjF516lRiV10ia2B77TDrvBIDlt7CoChl/RZ OwhpW+c/W32Nfk75ctL+8KBdHoQqYaGhEswN47Ol05wGxsfdv9BhKyySWPBNJUE7LVcl wEtMJQc8iffbrA0fKS1e5xCxr/qs27f89+g1jATYH+BRz0CHR/cfu2drJ+vHerQH7nSP j7gnv5Z9gnHrIZ4nZXDmnNxna72RKE0DQnx3zdj/1+0hC/nxWFM07hFm+R6a5iB3F+93 kKCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q10DS0Ut; 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 w18si5087359ejy.196.2021.03.08.12.42.51; Mon, 08 Mar 2021 12:43:15 -0800 (PST) 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=Q10DS0Ut; 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 S230457AbhCHUlu (ORCPT + 99 others); Mon, 8 Mar 2021 15:41:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:34248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbhCHUlc (ORCPT ); Mon, 8 Mar 2021 15:41:32 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A37365272; Mon, 8 Mar 2021 20:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615236091; bh=xOjktTqUitc+u1lOxtaIEmtkCUS5Jbq0EmElj0l8lV0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q10DS0UtjUUmLvXYNaUX3vwPngvfe7lurRbXNzKnAiWlO7g1p9N2VaaXLXNkiGHk5 isvxwEDp7HIiUqCiKNjdc9QltPw735qpEpZ1TvcfuHzsSDgjtX28Lk7KC1aJmMsLRa ibfaGioCMssSiSasd5VfrJZ+ClxHRugUZquKR4P2UPxBJ7RKH7fnnf3GorIDhjt45n AKUkLRLxuInqHpLM5XlxOOLiavSlM/hZpC0/wIf4f9EL8kcDte3CDInpGrxvBcrEa2 GVIi0B4qgto4IBfgHynXSihi6bK95g8MpkSah8oTfWV8z4ZYnlEfB+0w0dRtAAaR1m SV3b9kR09lL8A== Date: Mon, 8 Mar 2021 14:41:29 -0600 From: "Gustavo A. R. Silva" To: James Bottomley Cc: Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , "Martin K. Petersen" , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2][next] scsi: mpt3sas: Replace one-element array with flexible-array in struct _MPI2_CONFIG_PAGE_IO_UNIT_3 Message-ID: <20210308204129.GA214076@embeddedor> References: <20210202235118.GA314410@embeddedor> <20210308193237.GA212624@embeddedor> <88d9dda39a70df25b48e72247b9752d3dc5e2e8d.camel@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <88d9dda39a70df25b48e72247b9752d3dc5e2e8d.camel@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 08, 2021 at 12:12:59PM -0800, James Bottomley wrote: > On Mon, 2021-03-08 at 13:32 -0600, Gustavo A. R. Silva wrote: > > Hi all, > > > > Friendly ping: who can review/take this, please? > > Well, before embarking on a huge dynamic update, let's ask Broadcom the > simpler question of why isn't MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX simply > set to 36? There's no dynamic allocation of anything in the current > code ... it's all hard coded to allocate 36 entries. If there's no > need for anything dynamic then the kzalloc could become Yeah; and if that is the case, then there is no even need for kzalloc() at all, and it can be replaced by memset(): diff --git a/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h b/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h index 43a3bf8ff428..d00431f553e1 100644 --- a/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h +++ b/drivers/scsi/mpt3sas/mpi/mpi2_cnfg.h @@ -992,7 +992,7 @@ typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_1 { *one and check the value returned for GPIOCount at runtime. */ #ifndef MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX -#define MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX (1) +#define MPI2_IO_UNIT_PAGE_3_GPIO_VAL_MAX (36) #endif typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_3 { diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c index 44f9a05db94e..23fcf29bfd67 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c +++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c @@ -3203,7 +3203,7 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr, { struct Scsi_Host *shost = class_to_shost(cdev); struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); - Mpi2IOUnitPage3_t *io_unit_pg3 = NULL; + Mpi2IOUnitPage3_t io_unit_pg3; Mpi2ConfigReply_t mpi_reply; u16 backup_rail_monitor_status = 0; u16 ioc_status; @@ -3221,16 +3221,10 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr, goto out; /* allocate upto GPIOVal 36 entries */ - sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36); - io_unit_pg3 = kzalloc(sz, GFP_KERNEL); - if (!io_unit_pg3) { - rc = -ENOMEM; - ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n", - __func__, sz); - goto out; - } + sz = sizeof(io_unit_pg3); + memset(&io_unit_pg3, 0, sz); - if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) != + if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, &io_unit_pg3, sz) != 0) { ioc_err(ioc, "%s: failed reading iounit_pg3\n", __func__); @@ -3246,19 +3240,18 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr, goto out; } - if (io_unit_pg3->GPIOCount < 25) { - ioc_err(ioc, "%s: iounit_pg3->GPIOCount less than 25 entries, detected (%d) entries\n", - __func__, io_unit_pg3->GPIOCount); + if (io_unit_pg3.GPIOCount < 25) { + ioc_err(ioc, "%s: iounit_pg3.GPIOCount less than 25 entries, detected (%d) entries\n", + __func__, io_unit_pg3.GPIOCount); rc = -EINVAL; goto out; } /* BRM status is in bit zero of GPIOVal[24] */ - backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]); + backup_rail_monitor_status = le16_to_cpu(io_unit_pg3.GPIOVal[24]); rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1)); out: - kfree(io_unit_pg3); mutex_unlock(&ioc->pci_access_mutex); return rc; } > > io_unit_pg3 = kzalloc(sizeof(*io_unit_pg3), GFP_KERNEL); > Thanks -- Gustavo