From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Felix Fietkau <nbd@nbd.name>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH mt76-next 03/20] wifi: mt76: mt7996: stop the hardware when the probe fails
Date: Sun, 29 Nov 2026 21:45:20 +0100 [thread overview]
Message-ID: <awyO4JSXfAQpoxxF@lore-desk> (raw)
In-Reply-To: <20261129193131.3367661-3-nbd@nbd.name>
[-- Attachment #1: Type: text/plain, Size: 6634 bytes --]
> 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 <nbd@nbd.name>
Reviewed-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> .../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
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-11-29 20:45 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 19:31 [PATCH mt76-next 01/20] wifi: mt76: mt7996: hold the wiphy lock in the L1 SER reset work Felix Fietkau
2026-11-29 19:31 ` [PATCH mt76-next 02/20] wifi: mt76: mt7996: report the TX statistics of each link of a station Felix Fietkau
2026-11-29 20:51 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 03/20] wifi: mt76: mt7996: stop the hardware when the probe fails Felix Fietkau
2026-11-29 20:45 ` Lorenzo Bianconi [this message]
2026-11-29 19:31 ` [PATCH mt76-next 04/20] wifi: mt76: mt7996: clean up the DMA when the NPU RX queue init fails Felix Fietkau
2026-11-29 20:36 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 05/20] wifi: mt76: mt7996: name the link and the error of a failed key install Felix Fietkau
2026-11-29 20:42 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 06/20] wifi: mt76: mt7925: send the HE capabilities of each link of a peer Felix Fietkau
2026-11-29 19:31 ` [PATCH mt76-next 07/20] wifi: mt76: connac: mask the LDPC capabilities of an AP peer Felix Fietkau
2026-11-29 19:31 ` [PATCH mt76-next 08/20] wifi: mt76: mt7925: " Felix Fietkau
2026-11-29 19:31 ` [PATCH mt76-next 09/20] wifi: mt76: mt7996: read the EHT capabilities of a station as LE Felix Fietkau
2026-11-29 19:31 ` [PATCH mt76-next 10/20] wifi: mt76: mt7925: " Felix Fietkau
2026-11-29 20:47 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 11/20] wifi: mt76: mt7615: drop RX frame with a header gap past its end Felix Fietkau
2026-11-29 20:43 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 12/20] wifi: mt76: connac: drop a first fragment without an Ethernet header Felix Fietkau
2026-11-29 20:43 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 13/20] wifi: mt76: mt7915: drop RX frame with a header gap past its end Felix Fietkau
2026-11-29 20:47 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 14/20] wifi: mt76: mt7921: " Felix Fietkau
2026-11-29 20:47 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 15/20] wifi: mt76: mt7996: " Felix Fietkau
2026-11-29 20:51 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 16/20] wifi: mt76: mt7925: bound the header gap by the linear data of a frame Felix Fietkau
2026-11-29 20:45 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 17/20] wifi: mt76: mt7921: fix out-of-bounds read in mt7921_mac_add_txs Felix Fietkau
2026-11-29 20:42 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 18/20] wifi: mt76: mt7925: fix out-of-bounds read in mt7925_mac_add_txs Felix Fietkau
2026-11-29 20:41 ` Lorenzo Bianconi
2026-11-29 19:31 ` [PATCH mt76-next 19/20] wifi: mt76: mt7925: apply the dwell time of a scan request Felix Fietkau
2026-11-29 19:31 ` [PATCH mt76-next 20/20] wifi: mt76: connac: apply the dwell time of a scan request on mt7663 Felix Fietkau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awyO4JSXfAQpoxxF@lore-desk \
--to=lorenzo@kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=nbd@nbd.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox