wifi: brcmfmac: Fix potential kernel oops when probe fails
A message that is not in the archive (sent off-list or not yet received): CGME20260203102148eucas1p10c43be72827d74e5be41fe40a84fbd59@eucas1p1.samsung.com
PATCH v2 1/1 wifi: brcmfmac: Fix potential kernel oops when probe fails
When probe of the sdio brcmfmac device fails for some reasons (i.e. missing firmware), the sdiodev->bus is set to error instead of NULL, thus the cleanup later in brcmf_sdio_remove() tries to free resources via invalid bus pointer. This happens because sdiodev->bus is set 2 times:
first in brcmf_sdio_probe() and second time in brcmf_sdiod_probe(). Fix this by chaning the brcmf_sdio_probe() function to return the error code and set sdio->bus only there.
---
Changelog:
v2:
- changed return type of brcmf_sdio_probe() function
v1: https://lore.kernel.org/all/[email protected]
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 7 +++---- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 7 ++++--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c +3 -4
@@ -951,11 +951,10 @@ int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev) goto out;/* try to attach to the target device */ - sdiodev->bus =brcmf_sdio_probe (sdiodev); -if (IS_ERR (sdiodev->bus)) { - ret =PTR_ERR (sdiodev->bus); + ret =brcmf_sdio_probe (sdiodev); +if (ret) goto out; - } +brcmf_sdiod_host_fixup (sdiodev->func2->card->host); out:if (ret)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c +4 -3
@@ -4445,7 +4445,7 @@ brcmf_sdio_prepare_fw_request(struct brcmf_sdio *bus)return fwreq; } -struct brcmf_sdio *brcmf_sdio_probe (struct brcmf_sdio_dev *sdiodev) +int brcmf_sdio_probe (struct brcmf_sdio_dev *sdiodev) {int ret;struct brcmf_sdio *bus;
@@ -4551,11 +4551,12 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev) goto fail; } -return bus; +return 0 ; fail:brcmf_sdio_remove (bus); -return ERR_PTR (ret); + sdiodev->bus =NULL ; +return ret; }/* Detach and free everything */
drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h +1 -1
@@ -358,7 +358,7 @@ void brcmf_sdiod_freezer_uncount(struct brcmf_sdio_dev *sdiodev);int brcmf_sdiod_probe (struct brcmf_sdio_dev *sdiodev);int brcmf_sdiod_remove (struct brcmf_sdio_dev *sdiodev); -struct brcmf_sdio *brcmf_sdio_probe (struct brcmf_sdio_dev *sdiodev); +int brcmf_sdio_probe (struct brcmf_sdio_dev *sdiodev);void brcmf_sdio_remove (struct brcmf_sdio *bus);void brcmf_sdio_isr (struct brcmf_sdio *bus,bool in_isr);
Signature · 1 line
2.34.1
Arend van Spriel
maintainerQuoted 7 lines · Marek Szyprowski
When probe of the sdio brcmfmac device fails for some reasons (i.e. missing firmware), the
sdiodev->busis set to error instead of NULL, thus the cleanup later inbrcmf_sdio_remove()tries to free resources via invalid bus pointer. This happens becausesdiodev->busis set 2 times:
first inbrcmf_sdio_probe()and second time inbrcmf_sdiod_probe(). Fix this by chaning thebrcmf_sdio_probe()function to return the error code and setsdio->busonly there.
Looks much better, but wanted to see what was done in the commit referenced in the Fixes: tag.
Quoted 1 line
Fixes 0ff0843310b7 ("wifi: brcmfmac: Add optional lpo clock enable support")
So that patch wanted to propagate the result of devm_clk_get_optional_enabled() call in brcmf_of_probe():of.c to retry later. It ends up in brcmf_sdio_probe_attach() which is called in brcmf_sdio_probe(). Anyway, it seems okay to me. Will give it a spin in my setup just to be sure.
Thanks,
Arend
Quoted 10 lines · Arend van Spriel
Quoted 8 lines · Marek Szyprowski
When probe of the sdio brcmfmac device fails for some reasons (i.e. missing firmware), the
sdiodev->busis set to error instead of NULL, thus
the cleanup later inbrcmf_sdio_remove()tries to free resources via invalid bus pointer. This happens becausesdiodev->busis set 2 times:
first inbrcmf_sdio_probe()and second time inbrcmf_sdiod_probe(). Fix this by chaning thebrcmf_sdio_probe()function to return the error code and setsdio->busonly there.
Quoted 6 lines
Looks much better, but wanted to see what was done in the commit referenced in the Fixes: tag.
Quoted 2 lines
Fixes 0ff0843310b7 ("wifi: brcmfmac: Add optional lpo clock enablesupport")
That was the commit which introduced this regression, earlierbrcmf_sdio_probe() returned NULL in case of error and the check for sdio->bus was fine.
Quoted 6 lines
So that patch wanted to propagate the result of
devm_clk_get_optional_enabled()call in brcmf_of_probe():of.c to retry later. It ends up inbrcmf_sdio_probe_attach()which is called inbrcmf_sdio_probe(). Anyway, it seems okay to me. Will give it a spin in my setup just to be sure.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Op 3 februari 2026 11:21:51 schreef Marek Szyprowski <[email protected]>:
Quoted 9 lines
When probe of the sdio brcmfmac device fails for some reasons (i.e. missing firmware), the
sdiodev->busis set to error instead of NULL, thus the cleanup later inbrcmf_sdio_remove()tries to free resources via invalid bus pointer. This happens becausesdiodev->busis set 2 times:
first inbrcmf_sdio_probe()and second time inbrcmf_sdiod_probe(). Fix this by chaning thebrcmf_sdio_probe()function to return the error code and setsdio->busonly there.Fixes 0ff0843310b7 ("wifi: brcmfmac: Add optional lpo clock enable support")
Quoted 12 lines
Signed-off-by Marek Szyprowski <[email protected]>---
Changelog:
v2:
- changed return type ofbrcmf_sdio_probe()functionv1: https://lore.kernel.org/all/[email protected]
---drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 7 +++---- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 7 ++++--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-)