From: Jacob Keller <jacob.e.keller@intel.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Kalle Valo <kvalo@kernel.org>,
linux-wireless@vger.kernel.org,
Jacob Keller <jacob.e.keller@intel.com>,
Igor Mitsyanko <imitsyanko@quantenna.com>,
Sergey Matyukevich <geomatsi@gmail.com>
Subject: [PATCH 2/3] wifi: cfg80211: use struct_size and size_sub for payload length
Date: Tue, 28 Feb 2023 08:28:26 -0800 [thread overview]
Message-ID: <20230228162827.3876606-2-jacob.e.keller@intel.com> (raw)
In-Reply-To: <20230228162827.3876606-1-jacob.e.keller@intel.com>
Replace the calculations for the payload length in
qtnf_cmd_band_fill_iftype with struct_size() and size_sub(). While
the payload length does not get directly passed to an allocation function,
the performed calculation is still calculating the size of a flexible array
structure (minus the size of a header structure).
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Cc: Igor Mitsyanko <imitsyanko@quantenna.com>
Cc: Sergey Matyukevich <geomatsi@gmail.com>
---
drivers/net/wireless/quantenna/qtnfmac/commands.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/quantenna/qtnfmac/commands.c b/drivers/net/wireless/quantenna/qtnfmac/commands.c
index b1b73478d89b..68ae9c7ea95a 100644
--- a/drivers/net/wireless/quantenna/qtnfmac/commands.c
+++ b/drivers/net/wireless/quantenna/qtnfmac/commands.c
@@ -1325,9 +1325,10 @@ static int qtnf_cmd_band_fill_iftype(const u8 *data,
struct ieee80211_sband_iftype_data *iftype_data;
const struct qlink_tlv_iftype_data *tlv =
(const struct qlink_tlv_iftype_data *)data;
- size_t payload_len = tlv->n_iftype_data * sizeof(*tlv->iftype_data) +
- sizeof(*tlv) -
- sizeof(struct qlink_tlv_hdr);
+ size_t payload_len;
+
+ payload_len = struct_size(tlv, iftype_data, tlv->n_iftype_data);
+ payload_len = size_sub(payload_len, sizeof(struct qlink_tlv_hdr));
if (tlv->hdr.len != cpu_to_le16(payload_len)) {
pr_err("bad IFTYPE_DATA TLV len %u\n", tlv->hdr.len);
--
2.39.1.405.gd4c25cc71f83
next prev parent reply other threads:[~2023-02-28 16:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 16:28 [PATCH 1/3] wifi: ipw2x00: convert ipw_fw_error->elem to flexible array[] Jacob Keller
2023-02-28 16:28 ` Jacob Keller [this message]
2023-02-28 17:16 ` [PATCH 2/3] wifi: cfg80211: use struct_size and size_sub for payload length Johannes Berg
2023-02-28 16:28 ` [PATCH 3/3] wifi: nl80211: convert cfg80211_scan_request allocation to *_size macros Jacob Keller
2023-02-28 17:16 ` [PATCH 1/3] wifi: ipw2x00: convert ipw_fw_error->elem to flexible array[] Johannes Berg
2023-02-28 17:44 ` Jacob Keller
2023-02-28 17:46 ` Johannes Berg
2023-02-28 17:48 ` Jacob Keller
2023-03-01 20:49 ` Jacob Keller
2023-03-01 20:53 ` Johannes Berg
2023-03-01 21:01 ` Jacob Keller
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=20230228162827.3876606-2-jacob.e.keller@intel.com \
--to=jacob.e.keller@intel.com \
--cc=geomatsi@gmail.com \
--cc=imitsyanko@quantenna.com \
--cc=johannes@sipsolutions.net \
--cc=kvalo@kernel.org \
--cc=linux-wireless@vger.kernel.org \
/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