Skip to content

wifi: brcmfmac: pcie: don't arm a reset from a setup that fails - #65

Merged
derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:brcmfmac-setup-fail-reset
Oct 27, 2026
Merged

derekross merged 1 commit into
derekross:omamobilefrom
W4HO-ham:brcmfmac-setup-fail-reset

Conversation

@W4HO-ham

Copy link
Copy Markdown
Contributor

When brcmf_pcie_setup() fails it calls brcmf_fw_crashed(), which arms the bus reset, and then releases the driver. By the time brcmf_pcie_remove() drains the reset, the reset has already queued a new firmware request, and that request's brcmf_pcie_setup() runs while remove frees the chip. It oopses on devinfo->ci (NULL) in the firmware wait loop and leaves the reset and firmware workers stuck.

The fix blocks the reset before reporting the crash, as remove does. The coredump still happens, and nothing races the release.

I hit it on the palmtop (Pixel 9a, BCM4383) by suspending with brcmfmac loaded: hot resume finds the firmware crashed, the recovery download fails with "FW failed to initialize", and the second request oopsed at brcmf_pcie_setup+0x4d0. With this patch the same test ends with "Dongle setup failed", the driver released, no oops and nothing in D state.

Built with W=1 (no new warnings). checkpatch --strict is clean apart from the quoted oops line in the commit message.

When brcmf_pcie_setup() fails, it reports the crash with
brcmf_fw_crashed() and then releases the driver. brcmf_fw_crashed()
also arms the bus reset work. brcmf_pcie_remove(), called from
device_release_driver(), drains that work with
brcmf_bus_cancel_reset_work(); but by then the reset has usually run:
it detached the bus and queued a new firmware request. That request's
brcmf_pcie_setup() then runs while remove frees the chip, and it
dereferences devinfo->ci in the firmware wait loop of
brcmf_pcie_download_fw_nvram():

  Unable to handle kernel NULL pointer dereference at virtual address 000000000000001c
  pc : brcmf_pcie_setup+0x4d0/0x1008 [brcmfmac]
  Call trace:
   brcmf_pcie_setup+0x4d0/0x1008 [brcmfmac] (P)
   brcmf_fw_request_done+0x144/0x188 [brcmfmac]
   request_firmware_work_func+0x50/0xec

The reset work and the firmware workers stay stuck afterwards.

Block the reset before reporting the crash, as remove does: the driver
is released anyway, so the report keeps its coredump and nothing races
the release.

Found on a Pixel 9a (BCM4383) by suspending with the driver loaded: the
chip doesn't survive s2idle, the hot resume finds the firmware crashed,
the recovery reset's firmware download fails ("FW failed to
initialize"), and the second firmware request crashed as above. With
this change the same sequence ends with "Dongle setup failed", the
driver released, no oops and no task stuck in D state.

Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, this is right, and a nice catch. I traced it through: brcmf_fw_crashed() arms the reset through brcmf_bus_schedule_reset(), the reset work (brcmf_pcie_reset()) queues a fresh asynchronous firmware request and returns, and brcmf_pcie_remove() drains the work but can't drain the request it queued, then frees the chip. So the queued brcmf_pcie_setup() runs on freed state, which is the NULL devinfo->ci you saw. Setting removing before the crash report closes it, the coredump still runs, and the second cancel in remove is harmless. bus_reset_lock is initialised at probe before the first firmware request, so the first-probe path is fine too.

For the Pixel 7 Pro nothing changes in practice: I built pcie.o before and after and only brcmf_pcie_setup differs; on its one known setup failure the attach hasn't happened yet, so no reset was ever armed there, and our sleep hook unloads the driver rather than relying on the recovery reset.

This applies to mainline as it is: the removing gate is upstream and linux-next's brcmf_pcie_setup() fail path still has no cancel. If you send it there, add a Fixes: for the commit that introduced the reset-work gating. The checkpatch warning is only the quoted oops line.

Two small asks for next time, not for this one: the uname -r of the kernel the test ran on, and the blob id of pcie.c (git rev-parse <commit>:drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c), so the evidence is tied to a file we can read.

Gate passes on today's omamobile. It doesn't conflict with any of your other PRs (#56's pcie.c conflict is with the base and sits 700 lines away; now that the BCM4389 series is on omamobile, #56 can rebase). Merging.

@derekross
derekross merged commit 995ee63 into derekross:omamobile Oct 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants