From patchwork Fri Nov 18 23:47:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13049419 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 C75BAC433FE for ; Sat, 19 Nov 2022 00:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233420AbiKSApv (ORCPT ); Fri, 18 Nov 2022 19:45:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238016AbiKSApZ (ORCPT ); Fri, 18 Nov 2022 19:45:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A53C8D9B88; Fri, 18 Nov 2022 15:47:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 50AA7B825A6; Fri, 18 Nov 2022 23:47:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17700C433C1; Fri, 18 Nov 2022 23:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668815246; bh=XihwsWyiavzhVTmCCaUHQYkuUf+CaFnN21aKdYIXar8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MVLvZFVNR7rHcvbYuWk2IjlI/cpfz1iiyjTD0+2eaw6EHhqbW6MdRkCnCYdCtKlwS dwCkKmNYalqrgmln9eonH8/BAU3fDNvfT7z0Hzt7py4JSqrh3bnHrpgLo6reswibnH tISCTpcVwkKUKyWshudzZ9dvv47D0uD05qR0hKGXjwIJ1nx55LC2mNVcf6nqTvhMyL ECD5cpnLk3glAjZt7sHjCLg7FR8w75cwLAorze4WLNPKh+y4uiTdB1jflVllU5x2o4 npYEn0hF/B5bYLa0o14PWysnyhBBy0aBf+yfae3usfPKN9AoLdfTGdd2nMbDDkws0y 3D4Wd/spUdOFQ== Date: Fri, 18 Nov 2022 17:47:13 -0600 From: "Gustavo A. R. Silva" To: "Martin K. Petersen" , "James E.J. Bottomley" , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 1/2][next] scsi: qla2xxx: Replace one-element array with DECLARE_FLEX_ARRAY() helper Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org One-element arrays as fake flex arrays are deprecated and we are moving towards adopting C99 flexible-array members, instead. So, replace one-element array declaration in struct ct_sns_gpnft_rsp, which is ultimately being used inside a union: drivers/scsi/qla2xxx/qla_def.h: 3240 struct ct_sns_gpnft_pkt { 3241 union { 3242 struct ct_sns_req req; 3243 struct ct_sns_gpnft_rsp rsp; 3244 } p; 3245 }; Important to mention is that doing a build before/after this patch results in no binary differences. This help us make progress towards globally enabling -fstrict-flex-arrays=3 [1]. Link: https://github.com/KSPP/linux/issues/245 Link: https://github.com/KSPP/linux/issues/193 Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1] Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/scsi/qla2xxx/qla_def.h | 4 ++-- drivers/scsi/qla2xxx/qla_gs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h index a26a373be9da..1eea977ef426 100644 --- a/drivers/scsi/qla2xxx/qla_def.h +++ b/drivers/scsi/qla2xxx/qla_def.h @@ -3151,12 +3151,12 @@ struct ct_sns_gpnft_rsp { uint8_t vendor_unique; }; /* Assume the largest number of targets for the union */ - struct ct_sns_gpn_ft_data { + DECLARE_FLEX_ARRAY(struct ct_sns_gpn_ft_data { u8 control_byte; u8 port_id[3]; u32 reserved; u8 port_name[8]; - } entries[1]; + }, entries); }; /* CT command response */ diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c index 64ab070b8716..69d3bc795f90 100644 --- a/drivers/scsi/qla2xxx/qla_gs.c +++ b/drivers/scsi/qla2xxx/qla_gs.c @@ -4073,7 +4073,7 @@ int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type, srb_t *sp) sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE; rspsz = sizeof(struct ct_sns_gpnft_rsp) + - ((vha->hw->max_fibre_devices - 1) * + (vha->hw->max_fibre_devices * sizeof(struct ct_sns_gpn_ft_data)); sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, From patchwork Fri Nov 18 23:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 13049420 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 11594C4332F for ; Sat, 19 Nov 2022 00:46:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235516AbiKSAqI (ORCPT ); Fri, 18 Nov 2022 19:46:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237352AbiKSApo (ORCPT ); Fri, 18 Nov 2022 19:45:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 802B1DAD0E; Fri, 18 Nov 2022 15:48:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 39F19B8248E; Fri, 18 Nov 2022 23:48:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01D67C433C1; Fri, 18 Nov 2022 23:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668815290; bh=V6o1820BomTbYwPBPVjRJZa37GdSnz96MLHX9Zwoc3Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hBIzxcJR6aLIxyVUmvLdDSGGutCg/6lET7G/314fgO3kvLNmmF8kKssti9L7Fol2F X17ZYJcubbxZvm7nAGmAJ1n0ElFvafZUOmFBXtAquLbYodrSwzncW+SR4q0zI4/xsn EzoZZb2RAJ6CAVBAD0sYcblNDKCIpBw4eJ16FLgBecV9ZNJqZD2DeLJBXuhacHlTeW o8UI0rd4BgJ6a4J4QXcvVWhc+bXDU3lNuWVxnJKt32gD54K6GI3NvGqJTnEzsxGgJQ mpPdXqLwHyYtigG2PEvXMsTp5mpcPC/mMQL/7/smpB53PMJXRI7/nRGOi52pdmdDvn qB5irgaJNHK6w== Date: Fri, 18 Nov 2022 17:47:56 -0600 From: "Gustavo A. R. Silva" To: "Martin K. Petersen" , "James E.J. Bottomley" , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 2/2][next] scsi: qla2xxx: Use struct_size() in code related to struct ct_sns_gpnft_rsp Message-ID: <9bd4775fe9c88b33c3194f841a2ec2f559d58032.1668814746.git.gustavoars@kernel.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Prefer struct_size() over open-coded versions of idiom: sizeof(struct-with-flex-array) + sizeof(typeof-flex-array-elements) * count where count is the max number of items the flexible array is supposed to contain. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva --- drivers/scsi/qla2xxx/qla_gs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/qla2xxx/qla_gs.c b/drivers/scsi/qla2xxx/qla_gs.c index 69d3bc795f90..27e1df56b0fb 100644 --- a/drivers/scsi/qla2xxx/qla_gs.c +++ b/drivers/scsi/qla2xxx/qla_gs.c @@ -4072,9 +4072,8 @@ int qla24xx_async_gpnft(scsi_qla_host_t *vha, u8 fc4_type, srb_t *sp) } sp->u.iocb_cmd.u.ctarg.req_size = GPN_FT_REQ_SIZE; - rspsz = sizeof(struct ct_sns_gpnft_rsp) + - (vha->hw->max_fibre_devices * - sizeof(struct ct_sns_gpn_ft_data)); + rspsz = struct_size((struct ct_sns_gpnft_rsp *)0, entries, + vha->hw->max_fibre_devices); sp->u.iocb_cmd.u.ctarg.rsp = dma_alloc_coherent(&vha->hw->pdev->dev, rspsz,