Linux kernel -stable discussions
 help / color / mirror / Atom feed
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 2/2] wifi: mwifiex: pcie: skip the card work once the adapter is gone
Date: Tue, 24 Nov 2026 09:59:32 +0900	[thread overview]
Message-ID: <20261124005935.290010-3-antoine.pichot@gmail.com> (raw)
In-Reply-To: <20261124005935.290010-1-antoine.pichot@gmail.com>

The work can also find card->adapter NULL without remove(), when
firmware initialisation fails at probe or after a reset. Both paths end
in the failure path of _mwifiex_fw_dpc(), which clears card->adapter and
frees the adapter:

- At probe, a command timeout during the initialisation queues a dump
  and a reset. The failure path clears card->adapter during the dump and
  waits for the work in mwifiex_cleanup_pcie(). The work then reads NULL
  for the reset.

- After a reset started by the work, the failure path runs inside the
  work, and it skips cancel_work_sync() while a PCI reset is ongoing
  since commit 4add4d988f95 ("mwifiex: pcie: skip cancel_work_sync() on
  reset failure path"). A timeout during the failed initialisation
  queues the work again, and it runs after the adapter is freed, with
  card->adapter NULL.

[1] reports four crashes in the card work on a Surface Pro 3 after the
driver's recovery from a firmware failure. In the reporter's kernel
build, all four are the work dereferencing a NULL card->adapter: three
in the reset branch and one at the start of the dump. This patch was not
tested on that machine. On a Surface Book 2 the unpatched driver crashed
on the probe path.

Read card->adapter when the work starts and return if it is NULL.
When remove() or the probe failure path tears the driver down, the
pointer stays valid while the work runs, since both wait for the work
before freeing the adapter. Skip the reset if card->adapter was cleared
during the dump: a teardown is then in progress. Pair it with
WRITE_ONCE() where card->adapter is set and cleared.

Tested on the Surface Book 2 (kernel 7.3.4) with a debug change that
drops one command during firmware initialisation, so that the command
timeout queues a dump and a reset and the initialisation fails. After a
failed runtime reset, the work queued again by the timeout found
card->adapter NULL and returned. At probe, the failure path cleared
card->adapter during the dump and the work skipped the reset. No crash
or warning in either case.

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.

Link: https://github.com/linux-surface/linux-surface/issues/2350 [1]
Fixes: 3860e5e39532 ("mwifiex: move pcie_work and related variables inside card")
Cc: stable@vger.kernel.org
Signed-off-by: Antoine Pichot <antoine.pichot@gmail.com>
---
 drivers/net/wireless/marvell/mwifiex/pcie.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/pcie.c b/drivers/net/wireless/marvell/mwifiex/pcie.c
index b63e6ac6e582..c4837102f0cd 100644
--- a/drivers/net/wireless/marvell/mwifiex/pcie.c
+++ b/drivers/net/wireless/marvell/mwifiex/pcie.c
@@ -2842,13 +2842,24 @@ static void mwifiex_pcie_work(struct work_struct *work)
 {
 	struct pcie_service_card *card =
 		container_of(work, struct pcie_service_card, work);
+	struct mwifiex_adapter *adapter = READ_ONCE(card->adapter);
+
+	/* The adapter is gone if a failed reset or probe has torn it
+	 * down.
+	 */
+	if (!adapter)
+		return;
 
 	if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
 			       &card->work_flags))
-		mwifiex_pcie_device_dump_work(card->adapter);
+		mwifiex_pcie_device_dump_work(adapter);
+	/* A teardown that started during the dump has cleared
+	 * card->adapter. Skip the reset, which would run into that
+	 * teardown.
+	 */
 	if (test_and_clear_bit(MWIFIEX_IFACE_WORK_CARD_RESET,
-			       &card->work_flags))
-		mwifiex_pcie_card_reset_work(card->adapter);
+			       &card->work_flags) && READ_ONCE(card->adapter))
+		mwifiex_pcie_card_reset_work(adapter);
 }
 
 /* This function dumps FW information */
@@ -3171,7 +3182,7 @@ static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
 	struct pcie_service_card *card = adapter->card;
 
 	/* save adapter pointer in card */
-	card->adapter = adapter;
+	WRITE_ONCE(card->adapter, adapter);
 
 	if (mwifiex_pcie_request_irq(adapter))
 		return -1;
@@ -3215,7 +3226,7 @@ static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
 		if (card->msi_enable)
 			pci_disable_msi(pdev);
 	}
-	card->adapter = NULL;
+	WRITE_ONCE(card->adapter, NULL);
 }
 
 /*
-- 
2.56.1


      parent reply	other threads:[~2026-11-24  0:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261124005935.290010-1-antoine.pichot@gmail.com>
2026-11-24  0:59 ` [PATCH wireless 1/2] wifi: mwifiex: pcie: stop the card work before tearing down the adapter Antoine Pichot
2026-11-24  0:59 ` Antoine Pichot [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=20261124005935.290010-3-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