From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Felix Fietkau <nbd@nbd.name>, Ryder Lee <ryder.lee@mediatek.com>,
Shayne Chen <shayne.chen@mediatek.com>,
Sean Wang <sean.wang@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: linux-wireless@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Lorenzo Bianconi <lorenzo@kernel.org>
Subject: [PATCH 2/2] wifi: mt76: npu: do not run mt76_npu_queue_cleanup() for not allocated queues
Date: Sun, 22 Nov 2026 12:09:15 +0100 [thread overview]
Message-ID: <20261122-mt76-npu-fixes-v1-2-8d8876b91970@kernel.org> (raw)
In-Reply-To: <20261122-mt76-npu-fixes-v1-0-8d8876b91970@kernel.org>
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@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
prev parent reply other threads:[~2026-11-22 11:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 11:09 [PATCH 0/2] wifi: mt76: add some npu missing fixes Lorenzo Bianconi
2026-11-22 11:09 ` [PATCH 1/2] wifi: mt76: npu: acquire queue lock running npu napi Lorenzo Bianconi
2026-11-22 11:09 ` Lorenzo Bianconi [this message]
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=20261122-mt76-npu-fixes-v1-2-8d8876b91970@kernel.org \
--to=lorenzo@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=ryder.lee@mediatek.com \
--cc=sean.wang@mediatek.com \
--cc=shayne.chen@mediatek.com \
/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