From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Kevin Barnett <kevin.barnett@microsemi.com>,
Don Brace <don.brace@microchip.com>,
storagedev@microchip.com,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.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 3/3][next] scsi: smartpqi: Use struct_size() helper in pqi_report_phys_luns()
Date: Wed, 21 Sep 2022 23:30:47 -0500 [thread overview]
Message-ID: <b6a23dbc136710e98580ac01daa39ad971eecb5d.1663816572.git.gustavoars@kernel.org> (raw)
In-Reply-To: <cover.1663816572.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/smartpqi/smartpqi_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 544cd18a90d7..17bdc8b3f161 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -1192,7 +1192,7 @@ static inline int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **b
rpl_8byte_wwid_list = rpl_list;
num_physicals = get_unaligned_be32(&rpl_8byte_wwid_list->header.list_length) / sizeof(rpl_8byte_wwid_list->lun_entries[0]);
- rpl_16byte_wwid_list_length = sizeof(struct report_lun_header) + (num_physicals * sizeof(struct report_phys_lun_16byte_wwid));
+ rpl_16byte_wwid_list_length = struct_size(rpl_16byte_wwid_list, lun_entries, num_physicals);
rpl_16byte_wwid_list = kmalloc(rpl_16byte_wwid_list_length, GFP_KERNEL);
if (!rpl_16byte_wwid_list)
--
2.34.1
next prev parent reply other threads:[~2022-09-22 4:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 4:26 [PATCH 0/3][next] scsi: smartpqi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2022-09-22 4:28 ` [PATCH 1/3][next] scsi: smartpqi: Replace one-element array with flexible-array member Gustavo A. R. Silva
2023-02-02 20:25 ` Kees Cook
[not found] ` <CY4PR11MB12387B9F495BC7B5D0F5FD84E1DA9@CY4PR11MB1238.namprd11.prod.outlook.com>
2023-02-06 22:28 ` Gustavo A. R. Silva
[not found] ` <CY4PR11MB123855C0E92965CD5B46C9B6E1DB9@CY4PR11MB1238.namprd11.prod.outlook.com>
2023-02-07 21:53 ` Gustavo A. R. Silva
2022-09-22 4:29 ` [PATCH 2/3][next] scsi: smartpqi: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2023-02-02 20:28 ` Kees Cook
2022-09-22 4:30 ` Gustavo A. R. Silva [this message]
2023-02-02 20:29 ` [PATCH 3/3][next] scsi: smartpqi: Use struct_size() helper in pqi_report_phys_luns() Kees Cook
2023-01-31 20:14 ` [PATCH 0/3][next] scsi: smartpqi: Replace one-element arrays with flexible-array members 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=b6a23dbc136710e98580ac01daa39ad971eecb5d.1663816572.git.gustavoars@kernel.org \
--to=gustavoars@kernel.org \
--cc=don.brace@microchip.com \
--cc=jejb@linux.ibm.com \
--cc=kevin.barnett@microsemi.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=storagedev@microchip.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
all inboxes | Powered by JetHome®