Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wifi: qtnfmac: use struct_size and size_sub for payload length

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

authored by

Jacob Keller and committed by
Kalle Valo
84e9e210 a23c82e0

+4 -3
+4 -3
drivers/net/wireless/quantenna/qtnfmac/commands.c
··· 1325 1325 struct ieee80211_sband_iftype_data *iftype_data; 1326 1326 const struct qlink_tlv_iftype_data *tlv = 1327 1327 (const struct qlink_tlv_iftype_data *)data; 1328 - size_t payload_len = tlv->n_iftype_data * sizeof(*tlv->iftype_data) + 1329 - sizeof(*tlv) - 1330 - sizeof(struct qlink_tlv_hdr); 1328 + size_t payload_len; 1329 + 1330 + payload_len = struct_size(tlv, iftype_data, tlv->n_iftype_data); 1331 + payload_len = size_sub(payload_len, sizeof(struct qlink_tlv_hdr)); 1331 1332 1332 1333 if (tlv->hdr.len != cpu_to_le16(payload_len)) { 1333 1334 pr_err("bad IFTYPE_DATA TLV len %u\n", tlv->hdr.len);