From: Antoine Pichot <antoine.pichot@gmail.com>
To: Brian Norris <briannorris@chromium.org>,
Francesco Dolcini <francesco@dolcini.it>
Cc: Antoine Pichot <antoine.pichot@gmail.com>,
linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
Andreas Kemnade <andreas@kemnade.info>,
stable@vger.kernel.org
Subject: [PATCH wireless 1/2] wifi: mwifiex: pcie: stop the card work before tearing down the adapter
Date: Tue, 24 Nov 2026 09:59:31 +0900 [thread overview]
Message-ID: <20261124005935.290010-2-antoine.pichot@gmail.com> (raw)
In-Reply-To: <20261124005935.290010-1-antoine.pichot@gmail.com>
If the firmware does not answer the shutdown command sent by
mwifiex_pcie_remove(), mwifiex_cmd_timeout_func() queues a firmware dump
and a card reset on card->work. remove() continues into
mwifiex_remove_card(), which clears card->adapter and frees the
interfaces while the dump runs. When the dump ends, the work reads
card->adapter for the reset and dereferences NULL:
mwifiex_pcie 0000:01:00.0: mwifiex_cmd_timeout_func: Timeout cmd id = 0xaa, act = 0x0
mwifiex_pcie 0000:01:00.0: info: shutdown mwifiex...
mwifiex_pcie 0000:01:00.0: == mwifiex firmware dump start ==
BUG: kernel NULL pointer dereference, address: 0000000000000088
Workqueue: events mwifiex_pcie_work [mwifiex_pcie]
RIP: 0010:mwifiex_pcie_work+0x87/0xc0 [mwifiex_pcie]
This crashed a Surface Book 2 (88W8897) at shutdown four times in about
400 reboots; the three crashes with a full log went through
mwifiex_pcie_shutdown().
The teardown waits for the work in mwifiex_cleanup_pcie(), but only
after card->adapter is cleared. Commit b713bbf1471b ("mwifiex: cancel
pcie/sdio work in remove/shutdown handler") cancelled the work earlier
in remove() for this crash. Commit 7e34c0d2f631 ("Revert "mwifiex:
cancel pcie/sdio work in remove/shutdown handler"") reverted it, saying
that since commit b014e96d1abb ("PCI: Protect
pci_error_handlers->reset_notify() usage with device_lock()") a reset
cannot run during remove(), and that the work then waited in
pci_reset_function() for the device lock that remove() holds. The device
lock does not cover the dump, nor the read of card->adapter before the
reset. Since commit a64e7a79dd60 ("mwifiex: resolve reset vs.
remove()/shutdown() deadlocks"), the work only tries to take that lock,
so remove() can wait for it before the teardown again.
Use disable_work_sync() rather than cancel_work_sync(), so that a
timeout or a debugfs reset request during the teardown cannot queue the
work again. The card is allocated at probe, so a later bind starts with
a new work. When the firmware does not answer the shutdown command,
remove() already waited for the dump that the timeout starts (about 46 s
on the 88W8897), in mwifiex_cleanup_pcie(); it now waits before the
teardown instead. A dump still waiting in the queue is cancelled.
remove() also returns early when a failed reset or a failed probe left
no adapter. The work can still be queued then: a failed reset queues it
again from inside it, and the teardown of a failed probe stops the
command timer only after waiting for the work. Wait for it there too,
before the card is freed.
Tested on the Surface Book 2 with a debug change that queues the dump
and the reset in remove() right after the shutdown command. Without this
patch (kernel 7.2.15) the work found card->adapter NULL in 3 runs out of
3. With it (kernel 7.3.4, before the wait on the early return was added;
the main path is unchanged), and a 200 ms pause so that the dump was
already running when remove() reached the wait, remove() waited for the
dump (about 46 s) and the teardown completed cleanly in 5 runs out of 5.
With patch 2 also applied, a debug change that makes a reset fail (it
drops one command during firmware initialisation, so that the command
timeout queues the work again and the initialisation fails), and a 5 s
pause in the work when it finds no adapter, remove() took the early
return while that work was running, and returned only after it.
Found, written and tested with an AI coding assistant (Claude Code with
Claude Opus 5.5) under my direction; I reviewed the patch and the test
results.
Fixes: 7e34c0d2f631 ("Revert "mwifiex: cancel pcie/sdio work in remove/shutdown handler"")
Cc: stable@vger.kernel.org # 6.10+
Signed-off-by: Antoine Pichot <antoine.pichot@gmail.com>
---
drivers/net/wireless/marvell/mwifiex/pcie.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
index ecbe864b0797..b63e6ac6e582 100644
--- a/drivers/net/wireless/marvell/mwifiex/pcie.c
+++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
@@ -437,8 +437,14 @@ static void mwifiex_pcie_remove(struct pci_dev *pdev)
wait_for_completion(&card->fw_done);
adapter = card->adapter;
- if (!adapter || !adapter->priv_num)
+ if (!adapter || !adapter->priv_num) {
+ /* The adapter is gone, but a failed reset or probe can have
+ * queued the work again, and the card it runs on is freed
+ * when remove() returns.
+ */
+ disable_work_sync(&card->work);
return;
+ }
reg = card->pcie.reg;
if (reg)
@@ -456,6 +462,13 @@ static void mwifiex_pcie_remove(struct pci_dev *pdev)
mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
}
+ /* A timeout of the commands above queues a firmware dump and a card
+ * reset on card->work. Wait for it and keep it from being queued
+ * again before the teardown clears card->adapter and frees the
+ * interfaces the dump reads.
+ */
+ disable_work_sync(&card->work);
+
mwifiex_remove_card(adapter);
}
--
2.56.1
next prev parent reply other threads:[~2026-11-24 0:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 0:59 [PATCH wireless 0/2] wifi: mwifiex: pcie: fix NULL dereferences in the card work at teardown Antoine Pichot
2026-11-24 0:59 ` Antoine Pichot [this message]
2026-11-24 0:59 ` [PATCH wireless 2/2] wifi: mwifiex: pcie: skip the card work once the adapter is gone Antoine Pichot
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=20261124005935.290010-2-antoine.pichot@gmail.com \
--to=antoine.pichot@gmail.com \
--cc=andreas@kemnade.info \
--cc=briannorris@chromium.org \
--cc=francesco@dolcini.it \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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