Skip to content

Commit cc0c53f

Browse files
keesjmberg-intel
authored andcommitted
wifi: iwlwifi: mvm: Fix __counted_by usage in cfg80211_wowlan_nd_*
Both struct cfg80211_wowlan_nd_match and struct cfg80211_wowlan_nd_info pre-allocate space for channels and matches, but then may end up using fewer that the full allocation. Shrink the associated counter (n_channels and n_matches) after counting the results. This avoids compile-time (and run-time) warnings from __counted_by. (The counter member needs to be updated _before_ accessing the array index.) Seen with coming GCC 15: drivers/net/wireless/intel/iwlwifi/mvm/d3.c: In function 'iwl_mvm_query_set_freqs': drivers/net/wireless/intel/iwlwifi/mvm/d3.c:2877:66: warning: operation on 'match->n_channels' may be undefined [-Wsequence-point] 2877 | match->channels[match->n_channels++] = | ~~~~~~~~~~~~~~~~~^~ drivers/net/wireless/intel/iwlwifi/mvm/d3.c:2885:66: warning: operation on 'match->n_channels' may be undefined [-Wsequence-point] 2885 | match->channels[match->n_channels++] = | ~~~~~~~~~~~~~~~~~^~ drivers/net/wireless/intel/iwlwifi/mvm/d3.c: In function 'iwl_mvm_query_netdetect_reasons': drivers/net/wireless/intel/iwlwifi/mvm/d3.c:2982:58: warning: operation on 'net_detect->n_matches' may be undefined [-Wsequence-point] 2982 | net_detect->matches[net_detect->n_matches++] = match; | ~~~~~~~~~~~~~~~~~~~~~^~ Cc: [email protected] Fixes: aa4ec06 ("wifi: cfg80211: use __counted_by where appropriate") Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent b83accf commit cc0c53f

File tree

1 file changed

+11
-3
lines changed
  • drivers/net/wireless/intel/iwlwifi/mvm

1 file changed

+11
-3
lines changed

drivers/net/wireless/intel/iwlwifi/mvm/d3.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,7 @@ static void iwl_mvm_query_set_freqs(struct iwl_mvm *mvm,
29542954
int idx)
29552955
{
29562956
int i;
2957+
int n_channels = 0;
29572958

29582959
if (fw_has_api(&mvm->fw->ucode_capa,
29592960
IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
@@ -2962,17 +2963,19 @@ static void iwl_mvm_query_set_freqs(struct iwl_mvm *mvm,
29622963

29632964
for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; i++)
29642965
if (matches[idx].matching_channels[i / 8] & (BIT(i % 8)))
2965-
match->channels[match->n_channels++] =
2966+
match->channels[n_channels++] =
29662967
mvm->nd_channels[i]->center_freq;
29672968
} else {
29682969
struct iwl_scan_offload_profile_match_v1 *matches =
29692970
(void *)results->matches;
29702971

29712972
for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 * 8; i++)
29722973
if (matches[idx].matching_channels[i / 8] & (BIT(i % 8)))
2973-
match->channels[match->n_channels++] =
2974+
match->channels[n_channels++] =
29742975
mvm->nd_channels[i]->center_freq;
29752976
}
2977+
/* We may have ended up with fewer channels than we allocated. */
2978+
match->n_channels = n_channels;
29762979
}
29772980

29782981
/**
@@ -3053,6 +3056,8 @@ static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
30533056
GFP_KERNEL);
30543057
if (!net_detect || !n_matches)
30553058
goto out_report_nd;
3059+
net_detect->n_matches = n_matches;
3060+
n_matches = 0;
30563061

30573062
for_each_set_bit(i, &matched_profiles, mvm->n_nd_match_sets) {
30583063
struct cfg80211_wowlan_nd_match *match;
@@ -3066,8 +3071,9 @@ static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
30663071
GFP_KERNEL);
30673072
if (!match)
30683073
goto out_report_nd;
3074+
match->n_channels = n_channels;
30693075

3070-
net_detect->matches[net_detect->n_matches++] = match;
3076+
net_detect->matches[n_matches++] = match;
30713077

30723078
/* We inverted the order of the SSIDs in the scan
30733079
* request, so invert the index here.
@@ -3082,6 +3088,8 @@ static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
30823088

30833089
iwl_mvm_query_set_freqs(mvm, d3_data->nd_results, match, i);
30843090
}
3091+
/* We may have fewer matches than we allocated. */
3092+
net_detect->n_matches = n_matches;
30853093

30863094
out_report_nd:
30873095
wakeup.net_detect = net_detect;

0 commit comments

Comments
 (0)