mt76_reset_device() runs INIT_LIST_HEAD() on dev->sta_poll_list while wcids that are not in dev->wcid[] can still be on it, such as a station between .sta_pre_rcu_remove and its removal. The later removal of such a station then corrupts the list. Take the remaining wcids off the list under sta_poll_lock. While here, drop the comment in mt76_wcid_cleanup() that names the re-initialisation. Fixes: 065c79df595a ("wifi: mt76: mt7915: fix list corruption after hardware restart") Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/mac80211.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index 85491727dc30..3f31ce188276 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -922,7 +922,12 @@ void mt76_reset_device(struct mt76_dev *dev) rcu_read_unlock(); INIT_LIST_HEAD(&dev->wcid_list); - INIT_LIST_HEAD(&dev->sta_poll_list); + + spin_lock_bh(&dev->sta_poll_lock); + while (!list_empty(&dev->sta_poll_list)) + list_del_init(dev->sta_poll_list.next); + spin_unlock_bh(&dev->sta_poll_lock); + dev->vif_mask = 0; memset(dev->wcid_mask, 0, sizeof(dev->wcid_mask)); @@ -1864,11 +1869,6 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid) idr_destroy(&wcid->pktid); mt76_tx_status_unlock(dev, &list); - /* Remove from sta_poll_list to prevent list corruption after reset. - * Without this, mt76_reset_device() reinitializes sta_poll_list but - * leaves wcid->poll_list with stale pointers, causing list corruption - * when mt76_wcid_add_poll() checks list_empty(). - */ spin_lock_bh(&dev->sta_poll_lock); if (!list_empty(&wcid->poll_list)) list_del_init(&wcid->poll_list); -- 2.47.3