Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp526829ybi; Fri, 7 Jun 2019 12:03:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoUfL8Vwll4zEuwwXRFEdHS8aq6Ou5G9bHsaQrRAqe+c+eFSyJV7w0sHEsGKiYaPUIo9eo X-Received: by 2002:a17:90a:9dc5:: with SMTP id x5mr7181815pjv.110.1559934204553; Fri, 07 Jun 2019 12:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559934204; cv=none; d=google.com; s=arc-20160816; b=CZ8SBBRbp5CD3N6vIx1nbJHyKafK+B94SspwA0IdVY1vCaHNpfGsA8Nmn/A2uBL4Uk YkQZhFUCT5EXxWVOCI8IlEXAGBK+ncBu89egMu6BIduzqU5kvEAQdQOemThzE7Y9GaH+ ODEOm5TZwiZBxAcZL60A6/t3sxaIklFxohHthapWuO7Uxpys1AdghtMG298cW54sNUza 6cM/DakZTss50MGAe3ug/7Z4/BjrzlGkjHBe1AEHWkdIZqryZGlClhguxeXigK8r8nHM gHmpZryeyuUZK8gctvjZ5e9lneT8dhLTTwEKkQoR4w0MoTCgLoGx05PN2BgPgKItVV1n zqcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=yZ2xBnhlqmW32n/QHxZaL0Xo6PrWpJ/BCLYH/JiKHCc=; b=y33bNL2/4XjytDS4klhozT7GdDsHbTPo9Ns9J5P7GF1PY6pi727NysHnv0X5k08rPN iHYFv1z9pscM8aAggYcQUJxQutkre9zRbBCPP5qWnRn9zlx7sR0reR6xshqa8WjVs6AI gFF5vAv3y8FGv1iO8Q6Wh2lwf9Bwap0VWn3bknVr67QLdaDxQ/2O/HfbpgEDT789E81b Qg+1vDRTghG9/B1+nxWNgSxT6urRVOEYgRd5OHFdz4VuGz5mP3q5vG8duu1VGxUb3WQM W4HPTI4zHFNq3fmN3tPDFUL/nZgtpXlB+4OT7A/o64rnka+pBfZKduZzhN6mo3qOuMlZ c0hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gn11si2646801plb.119.2019.06.07.12.03.08; Fri, 07 Jun 2019 12:03:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730585AbfFGSk5 (ORCPT + 99 others); Fri, 7 Jun 2019 14:40:57 -0400 Received: from gateway21.websitewelcome.com ([192.185.45.163]:49194 "EHLO gateway21.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729449AbfFGSk5 (ORCPT ); Fri, 7 Jun 2019 14:40:57 -0400 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 4C133400C5A8B for ; Fri, 7 Jun 2019 13:40:56 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id ZJnMhDofg2PzOZJnMhXdKE; Fri, 07 Jun 2019 13:40:56 -0500 X-Authority-Reason: nr=8 Received: from [189.250.134.24] (port=46982 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.92) (envelope-from ) id 1hZJnL-002Ree-1F; Fri, 07 Jun 2019 13:40:55 -0500 Date: Fri, 7 Jun 2019 13:40:53 -0500 From: "Gustavo A. R. Silva" To: Kashyap Desai , Sumit Saxena , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" Cc: megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] scsi: megaraid_sas: Use struct_size() helper Message-ID: <20190607184053.GA11513@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.134.24 X-Source-L: No X-Exim-ID: 1hZJnL-002Ree-1F X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.134.24]:46982 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 8 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct MR_PD_CFG_SEQ_NUM_SYNC { ... struct MR_PD_CFG_SEQ seq[1]; } __packed; Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. So, replace the following form: sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)) with: struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1) This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c index a25b6b4b6548..56bd524dddbf 100644 --- a/drivers/scsi/megaraid/megaraid_sas_fusion.c +++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c @@ -1191,7 +1191,7 @@ megasas_ioc_init_fusion(struct megasas_instance *instance) int megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) { int ret = 0; - u32 pd_seq_map_sz; + size_t pd_seq_map_sz; struct megasas_cmd *cmd; struct megasas_dcmd_frame *dcmd; struct fusion_context *fusion = instance->ctrl_context; @@ -1200,9 +1200,7 @@ megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) { pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)]; pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)]; - pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + - (sizeof(struct MR_PD_CFG_SEQ) * - (MAX_PHYSICAL_DEVICES - 1)); + pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1); cmd = megasas_get_cmd(instance); if (!cmd) { -- 2.21.0