On a firmware crash recovery ath11k_mac_allocate() keeps the registered radios, but the error paths of ath11k_core_start() and ath11k_core_qmi_firmware_ready() still call ath11k_mac_destroy(). A failed recovery thus frees an ieee80211_hw that mac80211 still uses and leaves ab->pdevs[i].ar NULL. A frame bridged to the radio then follows the freed hw: Unable to handle kernel paging request at virtual address ffffff8316cfd480 pc : sta_info_hash_lookup+0x4c/0xe4 [mac80211] Call trace: sta_info_hash_lookup+0x4c/0xe4 [mac80211] (P) sta_info_get_bss+0x1c/0x78 [mac80211] ieee80211_lookup_ra_sta+0x124/0x14c [mac80211] __ieee80211_subif_start_xmit+0xb8/0x3a0 [mac80211] ieee80211_subif_start_xmit+0x50/0x750 [mac80211] dev_hard_start_xmit+0x98/0x120 and driver removal dereferences the NULL ar: Unable to handle kernel access to user memory outside uaccess routines at virtual address 0000000000000000 pc : ath11k_dp_rx_pdev_free+0x34/0x12c [ath11k] Call trace: ath11k_dp_rx_pdev_free+0x34/0x12c [ath11k] (P) ath11k_dp_pdev_free+0x4c/0x84 [ath11k] ath11k_core_deinit+0xdc/0x168 [ath11k] ath11k_ahb_remove+0x30/0x90 [ath11k_ahb] Destroy the radios only when ATH11K_FLAG_REGISTERED is clear, as ath11k_mac_allocate() does. ath11k_core_pdev_create() has the same problem with the registration. During a recovery ath11k_mac_register() and ath11k_debugfs_pdev_create() return early, but when a later step such as ath11k_spectral_init() or ath11k_cfr_init() fails, the error path calls ath11k_mac_unregister() and ath11k_debugfs_pdev_destroy(). The first unregisters the radios from mac80211 while ATH11K_FLAG_REGISTERED stays set, so driver removal unregisters them a second time. The second removes the debugfs tree of the device with the macN directories, while ar->debug.debugfs_pdev keeps pointing to the removed directory; the next recovery's ath11k_spectral_init() and ath11k_cfr_init() create their files under it. Undo both there only when ATH11K_FLAG_REGISTERED is clear as well, which is when this call did them. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Fixes: 0366f42640a4 ("ath11k: Move mac80211 hw allocation before wmi_init command") Signed-off-by: Julius Bairaktaris --- v3: also skip ath11k_mac_unregister() and ath11k_debugfs_pdev_destroy() in the error path of ath11k_core_pdev_create() while the device stays registered. Florian's Tested-by dropped, as the code changed. drivers/net/wireless/ath/ath11k/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index 8e4dab61a300..5f4e7fbe0b25 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -2073,11 +2073,13 @@ static int ath11k_core_pdev_create(struct ath11k_base *ab) err_thermal_unregister: ath11k_thermal_unregister(ab); err_mac_unregister: - ath11k_mac_unregister(ab); + if (!test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) + ath11k_mac_unregister(ab); err_dp_pdev_free: ath11k_dp_pdev_free(ab); err_pdev_debug: - ath11k_debugfs_pdev_destroy(ab); + if (!test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) + ath11k_debugfs_pdev_destroy(ab); return ret; } @@ -2231,7 +2233,8 @@ static int ath11k_core_start(struct ath11k_base *ab) err_reo_cleanup: ath11k_dp_pdev_reo_cleanup(ab); err_mac_destroy: - ath11k_mac_destroy(ab); + if (!test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) + ath11k_mac_destroy(ab); err_hif_stop: ath11k_hif_stop(ab); err_wmi_detach: @@ -2315,7 +2318,8 @@ int ath11k_core_qmi_firmware_ready(struct ath11k_base *ab) err_core_stop: ath11k_core_stop(ab); - ath11k_mac_destroy(ab); + if (!test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) + ath11k_mac_destroy(ab); err_dp_free: ath11k_dp_free(ab); mutex_unlock(&ab->core_lock); -- 2.53.0