mt7996_register_device() returns every error after mt7996_dma_init() with no teardown, and the probe then frees the device. A missing firmware or default EEPROM file is enough. The RX NAPIs stay enabled and thus stay in the global NAPI hash inside the freed memory. Each later napi_enable() whose id falls into one of their buckets then reads and writes freed memory. The DMA, the firmware and the NAPI threads are left running. An error of mt7996_coredump_register() also frees a registered hw. Stop the hardware on these errors as the remove path does. Where the hw was registered, unregister it first, like mt7915. Clear hw_init_done before that, so that no reset or dump work is queued during the teardown. Initialise the RRO MSDU page lists before the DMA init, since the teardown walks them also after a failed firmware load. Free the RRO buffers in the teardown after the DMA stop. With WED or NPU they are devres memory of that device, which the release of the PCI device does not free. The remove path shares the teardown. It thus frees the RRO buffers after the DMA stop, no longer before the NAPI disable. It also cancels reset_work and dump_work once more after the hw is unregistered. Fixes: 98686cd21624 ("wifi: mt76: mt7996: add driver for MediaTek Wi-Fi 7 (802.11be) devices") Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7996/init.c | 85 ++++++++++++------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/init.c b/drivers/net/wireless/mediatek/mt76/mt7996/init.c index dd7755f3258b..0363476ea708 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7996/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7996/init.c @@ -878,10 +878,6 @@ void mt7996_rro_hw_init(struct mt7996_dev *dev) if (!mt7996_has_hwrro(dev)) return; - INIT_LIST_HEAD(&dev->wed_rro.page_cache); - for (i = 0; i < ARRAY_SIZE(dev->wed_rro.page_map); i++) - INIT_LIST_HEAD(&dev->wed_rro.page_map[i]); - if (!is_mt7996(&dev->mt76)) { reg = MT_RRO_MSDU_PG_SEG_ADDR0; @@ -1274,9 +1270,29 @@ int mt7996_global_wcid_init(struct mt7996_dev *dev) return 0; } +static void mt7996_stop_hardware(struct mt7996_dev *dev) +{ + int i; + + cancel_work_sync(&dev->dump_work); + cancel_work_sync(&dev->reset_work); + for (i = 0; i < ARRAY_SIZE(dev->mt76.napi); i++) { + if (dev->mt76.napi[i].dev) + napi_disable(&dev->mt76.napi[i]); + } + mt7996_mcu_exit(dev); + mt7996_tx_token_put(dev); + mt7996_dma_cleanup(dev); + if (mt7996_has_hwrro(dev) && + !mtk_wed_device_active(&dev->mt76.mmio.wed)) + mt7996_rro_msdu_page_map_free(dev); + tasklet_disable(&dev->mt76.irq_tasklet); + mt7996_wed_rro_free(dev); +} + static int mt7996_init_hardware(struct mt7996_dev *dev) { - int ret; + int i, ret; mt76_wr(dev, MT_INT_SOURCE_CSR, ~0); if (is_mt7992(&dev->mt76)) { @@ -1287,6 +1303,9 @@ static int mt7996_init_hardware(struct mt7996_dev *dev) INIT_WORK(&dev->init_work, mt7996_init_work); INIT_WORK(&dev->wed_rro.work, mt7996_wed_rro_work); INIT_LIST_HEAD(&dev->wed_rro.poll_list); + INIT_LIST_HEAD(&dev->wed_rro.page_cache); + for (i = 0; i < ARRAY_SIZE(dev->wed_rro.page_map); i++) + INIT_LIST_HEAD(&dev->wed_rro.page_map[i]); spin_lock_init(&dev->wed_rro.lock); ret = mt7996_variant_type_init(dev); @@ -1301,21 +1320,30 @@ static int mt7996_init_hardware(struct mt7996_dev *dev) ret = mt7996_mcu_init(dev); if (ret) - return ret; + goto error; ret = mt7996_wed_rro_init(dev); if (ret) - return ret; + goto error; ret = mt7996_variant_fem_init(dev); if (ret) - return ret; + goto error; ret = mt7996_eeprom_init(dev); if (ret < 0) - return ret; + goto error; - return mt7996_global_wcid_init(dev); + ret = mt7996_global_wcid_init(dev); + if (ret) + goto error; + + return 0; + +error: + mt7996_stop_hardware(dev); + + return ret; } void mt7996_set_stream_vht_txbf_caps(struct mt7996_phy *phy) @@ -1777,22 +1805,22 @@ int mt7996_register_device(struct mt7996_dev *dev) ret = mt7996_register_phy(dev, MT_BAND1); if (ret) - return ret; + goto stop_hw; ret = mt7996_register_phy(dev, MT_BAND2); if (ret) - return ret; + goto stop_hw; ret = mt7996_npu_hw_init(dev); if (ret) - return ret; + goto stop_hw; mt7996_dma_rro_start(dev); ret = mt76_register_device(&dev->mt76, true, mt76_rates, ARRAY_SIZE(mt76_rates)); if (ret) - return ret; + goto stop_hw; mt7996_for_each_phy(dev, phy) mt7996_thermal_init(phy); @@ -1803,24 +1831,30 @@ int mt7996_register_device(struct mt7996_dev *dev) ret = mt7996_init_debugfs(dev); if (ret) - goto error; + goto unregister; ret = mt7996_coredump_register(dev); if (ret) - goto error; + goto unregister; return 0; -error: +unregister: + mt7996_set_hw_init_done(dev, false); cancel_work_sync(&dev->init_work); + cancel_work_sync(&dev->dump_work); + cancel_work_sync(&dev->reset_work); + mt7996_for_each_phy(dev, phy) + mt7996_unregister_thermal(phy); + mt76_unregister_device(&dev->mt76); +stop_hw: + mt7996_stop_hardware(dev); return ret; } void mt7996_unregister_device(struct mt7996_dev *dev) { - int i; - mt7996_set_hw_init_done(dev, false); cancel_work_sync(&dev->dump_work); cancel_work_sync(&dev->wed_rro.work); @@ -1831,18 +1865,7 @@ void mt7996_unregister_device(struct mt7996_dev *dev) mt7996_unregister_thermal(&dev->phy); mt7996_coredump_unregister(dev); mt76_unregister_device(&dev->mt76); - mt7996_wed_rro_free(dev); - for (i = 0; i < ARRAY_SIZE(dev->mt76.napi); i++) { - if (dev->mt76.napi[i].dev) - napi_disable(&dev->mt76.napi[i]); - } - mt7996_mcu_exit(dev); - mt7996_tx_token_put(dev); - mt7996_dma_cleanup(dev); - if (mt7996_has_hwrro(dev) && - !mtk_wed_device_active(&dev->mt76.mmio.wed)) - mt7996_rro_msdu_page_map_free(dev); - tasklet_disable(&dev->mt76.irq_tasklet); + mt7996_stop_hardware(dev); mt76_free_device(&dev->mt76); } -- 2.47.3