From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: "Martin K. Petersen" <martin.petersen@oracle.com>,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
GR-QLogic-Storage-Upstream@marvell.com,
Nilesh Javali <njavali@marvell.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-hardening@vger.kernel.org
Subject: [PATCH 2/2][next] scsi: qla2xxx: Use struct_size() in code related to struct ct_sns_gpnft_rsp
Date: Fri, 18 Nov 2022 17:47:56 -0600 [thread overview]
Message-ID: <9bd4775fe9c88b33c3194f841a2ec2f559d58032.1668814746.git.gustavoars@kernel.org> (raw)
In-Reply-To: <cover.1668814746.git.gustavoars@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 <gustavoars@kernel.org>
---
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,
--
2.34.1
next prev parent reply other threads:[~2022-11-19 0:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-18 23:46 [PATCH 0/2][next] scsi: qla2xxx: Replace one-element array with flexible-array member Gustavo A. R. Silva
2022-11-18 23:47 ` [PATCH 1/2][next] scsi: qla2xxx: Replace one-element array with DECLARE_FLEX_ARRAY() helper Gustavo A. R. Silva
2022-11-19 7:09 ` Kees Cook
2022-11-19 8:44 ` Christophe JAILLET
2022-11-19 8:56 ` Gustavo A. R. Silva
2022-11-19 10:23 ` Christophe JAILLET
2022-11-19 19:03 ` Gustavo A. R. Silva
2022-11-18 23:47 ` Gustavo A. R. Silva [this message]
2022-11-19 7:10 ` [PATCH 2/2][next] scsi: qla2xxx: Use struct_size() in code related to struct ct_sns_gpnft_rsp Kees Cook
2022-11-19 7:20 ` Gustavo A. R. Silva
2022-11-19 7:49 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9bd4775fe9c88b33c3194f841a2ec2f559d58032.1668814746.git.gustavoars@kernel.org \
--to=gustavoars@kernel.org \
--cc=GR-QLogic-Storage-Upstream@marvell.com \
--cc=jejb@linux.ibm.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=njavali@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).