2020-10-28 21:52:14

by Seung-Woo Kim

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

There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
by adding missed brcmf_free().

Reported-by: Jaehoon Chung <[email protected]>
Fixes: commit 450914c39f88 ("brcmfmac: split brcmf_attach() and brcmf_detach() functions")
Signed-off-by: Seung-Woo Kim <[email protected]>
Reviewed-by: Arend van Spriel <[email protected]>
---
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/[email protected]/
---
.../wireless/broadcom/brcm80211/brcmfmac/pcie.c | 6 ++++--
.../wireless/broadcom/brcm80211/brcmfmac/sdio.c | 1 +
2 files changed, 5 insertions(+), 2 deletions(-)

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)
--
1.7.4.1


2020-11-02 17:18:39

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2] brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free}

Seung-Woo Kim <[email protected]> writes:

> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
> by adding missed brcmf_free().
>
> Reported-by: Jaehoon Chung <[email protected]>
> 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.

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

2020-11-02 17:40:48

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH v2] brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free}

On November 2, 2020 6:15:32 PM Kalle Valo <[email protected]> wrote:

> Seung-Woo Kim <[email protected]> writes:
>
>> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
>> by adding missed brcmf_free().
>>
>> Reported-by: Jaehoon Chung <[email protected]>
>> 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




Attachments:
smime.p7s (4.08 kB)
S/MIME Cryptographic Signature

2020-11-02 17:46:48

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2] brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free}

Arend Van Spriel <[email protected]> writes:

> On November 2, 2020 6:15:32 PM Kalle Valo <[email protected]> wrote:
>
>> Seung-Woo Kim <[email protected]> writes:
>>
>>> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
>>> by adding missed brcmf_free().
>>>
>>> Reported-by: Jaehoon Chung <[email protected]>
>>> 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.

I'll then change it to:

Fixes: a1f5aac1765a ("brcmfmac: don't realloc wiphy during PCIe reset")

Is that ok?

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

2020-11-02 18:16:38

by Arend van Spriel

[permalink] [raw]
Subject: Re: [PATCH v2] brcmfmac: Fix memory leak for unpaired brcmf_{alloc/free}

On November 2, 2020 6:46:12 PM Kalle Valo <[email protected]> wrote:

> Arend Van Spriel <[email protected]> writes:
>
>> On November 2, 2020 6:15:32 PM Kalle Valo <[email protected]> wrote:
>>
>>> Seung-Woo Kim <[email protected]> writes:
>>>
>>>> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
>>>> by adding missed brcmf_free().
>>>>
>>>> Reported-by: Jaehoon Chung <[email protected]>
>>>> 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.
>
> I'll then change it to:
>
> Fixes: a1f5aac1765a ("brcmfmac: don't realloc wiphy during PCIe reset")
>
> Is that ok?

It is for me ;-)

Regards,
Arend



Attachments:
smime.p7s (4.08 kB)
S/MIME Cryptographic Signature

2020-11-07 16:20:28

by Kalle Valo

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

Seung-Woo Kim <[email protected]> wrote:

> There are missig brcmf_free() for brcmf_alloc(). Fix memory leak
> by adding missed brcmf_free().
>
> Reported-by: Jaehoon Chung <[email protected]>
> Fixes: a1f5aac1765a ("brcmfmac: don't realloc wiphy during PCIe reset")
> Signed-off-by: Seung-Woo Kim <[email protected]>
> Reviewed-by: Arend van Spriel <[email protected]>

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

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

--
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches