EMA beacon template retrieval fails when all non-transmitted profiles are removed because ieee80211_beacon_get_ap_ema_list() returns an error when 'beacon->mbssid_ies == NULL'. Modify the function to retrieve the default template even when no MBSSID elements are present. Use a separate iterator 'i' for the bcn[] loop and assign ema->cnt once after allocation, before any bcn[] access. This ensures correctness if bcn[] is ever annotated __counted_by(cnt), as the compiler would then require cnt to reflect the valid array bounds at every point of access. Signed-off-by: Aloka Dixit --- include/net/mac80211.h | 3 ++- net/mac80211/tx.c | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index f768ef9184eb..a825801fda50 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -5886,7 +5886,8 @@ struct ieee80211_ema_beacons { * This function follows the same rules as ieee80211_beacon_get_template() * but allocates and returns a pointer to list of all beacon templates required * to cover all profiles in the multiple BSSID set. Each template includes only - * one multiple BSSID element. + * one multiple BSSID element. If no MBSSID elements are present, this function + * will return the single default template. * * Driver must call ieee80211_beacon_free_ema_list() to free the memory. * diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index cb9ecac25a9c..50de2802f451 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -5843,27 +5843,33 @@ ieee80211_beacon_get_ap_ema_list(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *chanctx_conf) { struct ieee80211_ema_beacons *ema = NULL; + u8 cnt, i; - if (!beacon->mbssid_ies || !beacon->mbssid_ies->cnt) - return NULL; + if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) + cnt = beacon->mbssid_ies->cnt; + else + cnt = 1; - ema = kzalloc_flex(*ema, bcn, beacon->mbssid_ies->cnt, GFP_ATOMIC); + ema = kzalloc_flex(*ema, bcn, cnt, GFP_ATOMIC); if (!ema) return NULL; - for (ema->cnt = 0; ema->cnt < beacon->mbssid_ies->cnt; ema->cnt++) { - ema->bcn[ema->cnt].skb = + /* Set cnt before bcn[] access in case bcn[] gains __counted_by(cnt) */ + ema->cnt = cnt; + + for (i = 0; i < cnt; i++) { + ema->bcn[i].skb = ieee80211_beacon_get_ap(hw, vif, link, - &ema->bcn[ema->cnt].offs, + &ema->bcn[i].offs, is_template, beacon, - chanctx_conf, ema->cnt, NULL); - if (!ema->bcn[ema->cnt].skb) - break; + chanctx_conf, i, NULL); + if (!ema->bcn[i].skb) + goto free; } - if (ema->cnt == beacon->mbssid_ies->cnt) - return ema; + return ema; +free: ieee80211_beacon_free_ema_list(ema); return NULL; } --- base-commit: 18d0bedbb5f0538396cb7f763ed9cd1dd69c5b23 change-id: 20261002-ema-82877fcdc8d5 Best regards, -- Aloka Dixit