diff mbox series

[v2] brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free}

Message ID 1603849967-22817-1-git-send-email-sw0312.kim@samsung.com
State Superseded
Headers show
Series [v2] brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free} | expand

Commit Message

Seung-Woo Kim Oct. 28, 2020, 1:52 a.m. UTC
There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
by adding missed brcmf_free().

Reported-by: Jaehoon Chung <jh80.chung@samsung.com>
Fixes: commit 450914c39f88 ("brcmfmac: split brcmf_attach() and brcmf_detach() functions")
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
---
Change from v1 [1]
- add Fixes tag for the commit creating brcmf_alloc/free and unpaired path
- add Reviewd-by tag from Arend

[1] https://lore.kernel.org/linux-wireless/1603795630-14638-1-git-send-email-sw0312.kim@samsung.com/
---
 .../wireless/broadcom/brcm80211/brcmfmac/pcie.c    |    6 ++++--
 .../wireless/broadcom/brcm80211/brcmfmac/sdio.c    |    1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Arend van Spriel Nov. 2, 2020, 5:40 p.m. UTC | #1
On November 2, 2020 6:15:32 PM Kalle Valo <kvalo@codeaurora.org> wrote:

> Seung-Woo Kim <sw0312.kim@samsung.com> writes:
>
>> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
>> by adding missed brcmf_free().
>>
>> Reported-by: Jaehoon Chung <jh80.chung@samsung.com>
>> Fixes: commit 450914c39f88 ("brcmfmac: split brcmf_attach() and 
>> brcmf_detach() functions")
>
> This should be:
>
> Fixes: 450914c39f88 ("brcmfmac: split brcmf_attach() and brcmf_detach() 
> functions")
>
> But I can fix that, no need to resend because of this.

Hi Kalle,

But this is not the commit that needs fixing as I mentioned before. Instead 
it should be a1f5aac1765af ("brcmfmac: don't realloc wiphy during PCIe 
reset") which introduced the actual memory leak.

Regards,
Arend

> --
> https://patchwork.kernel.org/project/linux-wireless/list/
>
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Kalle Valo Nov. 7, 2020, 4:19 p.m. UTC | #2
Seung-Woo Kim <sw0312.kim@samsung.com> wrote:

> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
> by adding missed brcmf_free().
> 
> Reported-by: Jaehoon Chung <jh80.chung@samsung.com>
> Fixes: a1f5aac1765a ("brcmfmac: don't realloc wiphy during PCIe reset")
> Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
> Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>

Patch applied to wireless-drivers-next.git, thanks.

9db946284e07 brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free}
diff mbox series

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index 39381cb..d8db0db 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -1936,16 +1936,18 @@  static void brcmf_pcie_setup(struct device *dev, int ret,
 	fwreq = brcmf_pcie_prepare_fw_request(devinfo);
 	if (!fwreq) {
 		ret = -ENOMEM;
-		goto fail_bus;
+		goto fail_brcmf;
 	}
 
 	ret = brcmf_fw_get_firmwares(bus->dev, fwreq, brcmf_pcie_setup);
 	if (ret < 0) {
 		kfree(fwreq);
-		goto fail_bus;
+		goto fail_brcmf;
 	}
 	return 0;
 
+fail_brcmf:
+	brcmf_free(&devinfo->pdev->dev);
 fail_bus:
 	kfree(bus->msgbuf);
 	kfree(bus);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index 99987a7..59c2b2b 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -4541,6 +4541,7 @@  void brcmf_sdio_remove(struct brcmf_sdio *bus)
 		brcmf_sdiod_intr_unregister(bus->sdiodev);
 
 		brcmf_detach(bus->sdiodev->dev);
+		brcmf_free(bus->sdiodev->dev);
 
 		cancel_work_sync(&bus->datawork);
 		if (bus->brcmf_wq)