[PATCH 2/2] wifi: mt76: npu: do not run mt76_npu_queue_cleanup() for not allocated queues

Lorenzo Bianconi lorenzo at kernel.org
Sun Nov 22 03:09:15 PST 2026


mt76_npu_deinit() unconditionally calls mt76_npu_queue_cleanup() on the
NPU RX queues, even when the NPU is not active and the queues were never
allocated. In that case q->lock was never initialized by
mt76_dma_alloc_queue() and mt76_npu_queue_cleanup() takes a zeroed,
uninitialized spinlock. This is caught by CONFIG_DEBUG_SPINLOCK ("bad
magic") and lockdep, and is reachable on any mt76 device once
CONFIG_MT76_NPU is enabled, not just on NPU-capable ones.

Only call mt76_npu_queue_cleanup() when the queue was actually allocated,
i.e. when ndesc is set, matching the check already present in
mt76_dma_rx_cleanup(). Since mt76_dma_alloc_queue() initializes q->lock
before setting ndesc, a non-zero ndesc guarantees the lock is valid.

Run the cleanup while still holding dev->mutex so it is serialized with
the rest of the NPU teardown, keeping the dev->mutex -> q->lock order used
by mt76_npu_rx_queue_init().

Fixes: 7fb554b1b623 ("wifi: mt76: Introduce the NPU generic layer")
Signed-off-by: Lorenzo Bianconi <lorenzo at kernel.org>
---
 drivers/net/wireless/mediatek/mt76/npu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/npu.c b/drivers/net/wireless/mediatek/mt76/npu.c
index fbefc86001ff..af5bc3da26ab 100644
--- a/drivers/net/wireless/mediatek/mt76/npu.c
+++ b/drivers/net/wireless/mediatek/mt76/npu.c
@@ -554,8 +554,10 @@ void mt76_npu_deinit(struct mt76_dev *dev)
 	if (ppe_dev)
 		airoha_ppe_put_dev(ppe_dev);
 
-	mutex_unlock(&dev->mutex);
+	if (dev->q_rx[MT_RXQ_NPU0].ndesc)
+		mt76_npu_queue_cleanup(dev, &dev->q_rx[MT_RXQ_NPU0]);
+	if (dev->q_rx[MT_RXQ_NPU1].ndesc)
+		mt76_npu_queue_cleanup(dev, &dev->q_rx[MT_RXQ_NPU1]);
 
-	mt76_npu_queue_cleanup(dev, &dev->q_rx[MT_RXQ_NPU0]);
-	mt76_npu_queue_cleanup(dev, &dev->q_rx[MT_RXQ_NPU1]);
+	mutex_unlock(&dev->mutex);
 }

-- 
2.56.1




More information about the Linux-mediatek mailing list