Skip to content

Commit ef04a29

Browse files
committed
mac80211: handle station TX latency allocation errors
When the station's TX latency data structures need to be allocated, handle failures properly and also free all the structures if there are any other problems. Move the allocation code up so that allocation failures don't trigger rate control algorithm calls. Reported-by: ZHAO Gang <gamerh2o@gmail.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 4cd3c4e commit ef04a29

1 file changed

Lines changed: 40 additions & 30 deletions

File tree

‎net/mac80211/sta_info.c‎

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,35 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
300300
if (!sta)
301301
return NULL;
302302

303+
rcu_read_lock();
304+
tx_latency = rcu_dereference(local->tx_latency);
305+
/* init stations Tx latency statistics && TID bins */
306+
if (tx_latency) {
307+
sta->tx_lat = kzalloc(IEEE80211_NUM_TIDS *
308+
sizeof(struct ieee80211_tx_latency_stat),
309+
GFP_ATOMIC);
310+
if (!sta->tx_lat) {
311+
rcu_read_unlock();
312+
goto free;
313+
}
314+
315+
if (tx_latency->n_ranges) {
316+
for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
317+
/* size of bins is size of the ranges +1 */
318+
sta->tx_lat[i].bin_count =
319+
tx_latency->n_ranges + 1;
320+
sta->tx_lat[i].bins =
321+
kcalloc(sta->tx_lat[i].bin_count,
322+
sizeof(u32), GFP_ATOMIC);
323+
if (!sta->tx_lat[i].bins) {
324+
rcu_read_unlock();
325+
goto free;
326+
}
327+
}
328+
}
329+
}
330+
rcu_read_unlock();
331+
303332
spin_lock_init(&sta->lock);
304333
INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
305334
INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
@@ -324,10 +353,8 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
324353
for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
325354
ewma_init(&sta->chain_signal_avg[i], 1024, 8);
326355

327-
if (sta_prepare_rate_control(local, sta, gfp)) {
328-
kfree(sta);
329-
return NULL;
330-
}
356+
if (sta_prepare_rate_control(local, sta, gfp))
357+
goto free;
331358

332359
for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
333360
/*
@@ -371,34 +398,17 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
371398
}
372399
}
373400

374-
rcu_read_lock();
375-
376-
tx_latency = rcu_dereference(local->tx_latency);
377-
/* init stations Tx latency statistics && TID bins */
378-
if (tx_latency)
379-
sta->tx_lat = kzalloc(IEEE80211_NUM_TIDS *
380-
sizeof(struct ieee80211_tx_latency_stat),
381-
GFP_ATOMIC);
382-
383-
/*
384-
* if Tx latency and bins are enabled and the previous allocation
385-
* succeeded
386-
*/
387-
if (tx_latency && tx_latency->n_ranges && sta->tx_lat)
388-
for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
389-
/* size of bins is size of the ranges +1 */
390-
sta->tx_lat[i].bin_count =
391-
tx_latency->n_ranges + 1;
392-
sta->tx_lat[i].bins = kcalloc(sta->tx_lat[i].bin_count,
393-
sizeof(u32),
394-
GFP_ATOMIC);
395-
}
396-
397-
rcu_read_unlock();
398-
399401
sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
400-
401402
return sta;
403+
404+
free:
405+
if (sta->tx_lat) {
406+
for (i = 0; i < IEEE80211_NUM_TIDS; i++)
407+
kfree(sta->tx_lat[i].bins);
408+
kfree(sta->tx_lat);
409+
}
410+
kfree(sta);
411+
return NULL;
402412
}
403413

404414
static int sta_info_insert_check(struct sta_info *sta)

0 commit comments

Comments
 (0)