Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7047459ybi; Thu, 13 Jun 2019 08:41:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqy84DfVn5wJxRhOTpW7oqKeyEJXUw3BW0VkRQF7rEC+dIa2+QoF2vz1DuDwzo6jEksIcikN X-Received: by 2002:a63:ec02:: with SMTP id j2mr32291822pgh.340.1560440482980; Thu, 13 Jun 2019 08:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560440482; cv=none; d=google.com; s=arc-20160816; b=nFTr8xGZfbpRGxzRiLEGHDOwFayKqbdQBU8zv1tlBHMBBevAxV0Va6zK8NLcOvlshg 9Z2CPRTMwNYgwgco4l7hxmPJFHREv/SjEVSoSiwpj8Cd8K4pNdoUPaT+VVmAqtWhQSoN ALBsnN9TlMEooeNzCXA5S+YRT9YMA1PO+rD5fUVU0z3h88pYg2gfyskofxkYJHzsKpRM J9e9Sg/cdl/BEd6V0/HOj1qfQNVxUlFcqwPfi0/t1eUQFBAKl4FoAGonHZw8i835oNwO /fDmPoJEo+3r7muLVpNX2w+ty5PfnwaksiSkq/ro4I74Snf33zSgSdCmljPUWDLHnGJf rS0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Xbxjq+/UWnkmz/Lz2NuZarwVK3ifkKHPS3ppszMgh6E=; b=PhMt1AUZUVLdXB9rEf3Um184WnWfnq1R3Kupattq19OvrsbbBNx2c4UlJpwCwNExrC skmtFuxX3knuqjFUWdv/GI8BJq4ARN5SGNlQ5tZp0qzG9r3wXbOLFvh1UqjGLU7ltRgK +RZoT6ePQARUaNkEAwuGsyPRHhpsUTzAMmi1nGloQmZe+ovePMqVswV4qL+hvEFfS7jH dmuFfGStpzSrIQIzlFqJxxSt9BT325vjtXuPeAhALF59rfue3ESA18DKYiNkywdKyoel o9oimxhJx46MsRFd5fKDJj/Dr06jkme4eMJf4AkG6iXq+HCpJ9IiKmMQE7R0gV/PT1Vd NVIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=fEqFpleu; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si74777pgk.239.2019.06.13.08.41.08; Thu, 13 Jun 2019 08:41:22 -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; dkim=pass header.i=@broadcom.com header.s=google header.b=fEqFpleu; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731934AbfFMPjB (ORCPT + 99 others); Thu, 13 Jun 2019 11:39:01 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:45653 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731940AbfFMJ5q (ORCPT ); Thu, 13 Jun 2019 05:57:46 -0400 Received: by mail-vs1-f67.google.com with SMTP id n21so12223572vsp.12 for ; Thu, 13 Jun 2019 02:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Xbxjq+/UWnkmz/Lz2NuZarwVK3ifkKHPS3ppszMgh6E=; b=fEqFpleuGhOamNp5m2EH71DOiuFlFeO8LAoM/7Lp8TSo2eVpZ9KPxeKGpTLl5GjcwV S3d/AsmOzAXn2VmPPGGFecfnZaHbXbcxYJ+UVbXEz+fkjYrgIs2yGsUVg9uCX7fQmPrd Vshj30LgbeysHLD1OUon+3yIb+M7yDp2isl3Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Xbxjq+/UWnkmz/Lz2NuZarwVK3ifkKHPS3ppszMgh6E=; b=VBEliNNxkrbCUerilVhqn8kKiPuc/D5PmhSGvMlwkXLAN4ml9ahq9l0ZojIDSZKhcV E3//5QdaQVtG5uSrpt9kwSgQfnMRGPLBlz740TGBB70s7/V8/gIapjwHf/7tD+Lv3WdY Pcie3CbYj3vIa9kkhQL+Hrjgw9lRmBvSXne9NJk4pRuzG1JOrhEyNJQhzbR+TwkHKIUY 1z7vO/ZjgNSTPm16UCW6lL0j3EttDXH01s+20ZPBaHXvmDWTRRQS+Cxzl/LSTAU5LBSR zyxdkO8rnwQIqRAyEg58hox1hrQPUZl7HQWwXH2ZX8n0cF+QUcxJZcKZXMaT90BxSE3n 4Abw== X-Gm-Message-State: APjAAAXVXzKXquy8+bvy+uNxt5qUhpVN5/gXtbqhvL/E8kKQVX6b9+2J ZTdTKorKkFYQFGJC3dtkhGX53Xd+7YVbwec0oOrjdg== X-Received: by 2002:a67:ebcb:: with SMTP id y11mr8620799vso.138.1560419865266; Thu, 13 Jun 2019 02:57:45 -0700 (PDT) MIME-Version: 1.0 References: <20190607184053.GA11513@embeddedor> In-Reply-To: <20190607184053.GA11513@embeddedor> From: Sumit Saxena Date: Thu, 13 Jun 2019 15:27:33 +0530 Message-ID: Subject: Re: [PATCH] scsi: megaraid_sas: Use struct_size() helper To: "Gustavo A. R. Silva" Cc: Kashyap Desai , Shivasharan S , "James E.J. Bottomley" , "Martin K. Petersen" , "PDL,MEGARAIDLINUX" , Linux SCSI List , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 8, 2019 at 12:10 AM Gustavo A. R. Silva wrote: > > 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 Acked-by: Sumit Saxena > --- > 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 >