wifi: qtnfmac: use struct_size and size_sub for payload length
authorJacob Keller <jacob.e.keller@intel.com>
Tue, 7 Mar 2023 23:02:12 +0000 (15:02 -0800)
committerKalle Valo <kvalo@kernel.org>
Mon, 13 Mar 2023 13:44:29 +0000 (15:44 +0200)
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>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20230307230212.3735818-1-jacob.e.keller@intel.com
drivers/net/wireless/quantenna/qtnfmac/commands.c

index b1b7347..68ae9c7 100644 (file)
@@ -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);