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 X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 863FBC433E1 for ; Wed, 12 Aug 2020 01:36:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 41C4020658 for ; Wed, 12 Aug 2020 01:36:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="to+9+LZX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41C4020658 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DD3CD8D006F; Tue, 11 Aug 2020 21:36:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D84348D0001; Tue, 11 Aug 2020 21:36:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC2378D006F; Tue, 11 Aug 2020 21:36:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0172.hostedemail.com [216.40.44.172]) by kanga.kvack.org (Postfix) with ESMTP id B766F8D0001 for ; Tue, 11 Aug 2020 21:36:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 80D658248047 for ; Wed, 12 Aug 2020 01:36:42 +0000 (UTC) X-FDA: 77140202244.12.songs92_5f0df1226fe7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 5189118012B26 for ; Wed, 12 Aug 2020 01:36:42 +0000 (UTC) X-HE-Tag: songs92_5f0df1226fe7 X-Filterd-Recvd-Size: 3322 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 12 Aug 2020 01:36:41 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE45A2076C; Wed, 12 Aug 2020 01:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597196201; bh=yFDuguL2mEIHtTiYBxEYdk0/tp6+SdlMRYLyBQy3QpY=; h=Date:From:To:Subject:In-Reply-To:From; b=to+9+LZXEbEDYW++rMRyprahA+qz8CPjchoVL5NXo1/mdCUOkv1m4D8HGRAyYhS9z +zToBTHP0K39spa7RduzbaFzNVw98k8atcfMcmR12aYlMz7ZQse1gW4OGRkGK7HBnY aRzL7T1R7pAzK6ChI7Xc7dKKX5AM4CtE3GAX7ID0= Date: Tue, 11 Aug 2020 18:36:40 -0700 From: Andrew Morton To: akpm@linux-foundation.org, alex.bou9@gmail.com, gustavoars@kernel.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, mporter@kernel.crashing.org, torvalds@linux-foundation.org Subject: [patch 121/165] drivers/rapidio/rio-scan.c: use struct_size() helper Message-ID: <20200812013640.6i0R9Swhe%akpm@linux-foundation.org> In-Reply-To: <20200811182949.e12ae9a472e3b5e27e16ad6c@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 5189118012B26 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Gustavo A. R. Silva" Subject: drivers/rapidio/rio-scan.c: use struct_size() helper Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. Also, while there, use the preferred form for passing a size of a struct. The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed as argument is not. This issue was found with the help of Coccinelle and, audited and fixed manually. Addresses KSPP ID: https://github.com/KSPP/linux/issues/83 Link: http://lkml.kernel.org/r/20200619170445.GA22641@embeddedor Signed-off-by: Gustavo A. R. Silva Cc: Matt Porter Cc: Alexandre Bounine Signed-off-by: Andrew Morton --- drivers/rapidio/rio-scan.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/drivers/rapidio/rio-scan.c~rapidio-use-struct_size-helper +++ a/drivers/rapidio/rio-scan.c @@ -330,7 +330,7 @@ static struct rio_dev *rio_setup_device( size_t size; u32 swpinfo = 0; - size = sizeof(struct rio_dev); + size = sizeof(*rdev); if (rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR, &result)) return NULL; @@ -338,10 +338,8 @@ static struct rio_dev *rio_setup_device( if (result & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) { rio_mport_read_config_32(port, destid, hopcount, RIO_SWP_INFO_CAR, &swpinfo); - if (result & RIO_PEF_SWITCH) { - size += (RIO_GET_TOTAL_PORTS(swpinfo) * - sizeof(rswitch->nextdev[0])) + sizeof(*rswitch); - } + if (result & RIO_PEF_SWITCH) + size += struct_size(rswitch, nextdev, RIO_GET_TOTAL_PORTS(swpinfo)); } rdev = kzalloc(size, GFP_KERNEL); _