Re: [PATCH v4] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()

From: Philipp Hortmann
Date: Fri Sep 09 2022 - 13:31:45 EST


On 9/9/22 13:44, xkernel.wang@xxxxxxxxxxx wrote:
From: Xiaoke Wang <xkernel.wang@xxxxxxxxxxx>

In rtw_os_xmit_resource_alloc(), if usb_alloc_urb() fails, then the
memory `pxmitbuf_pallocated_buf` which is allocated by kzalloc() is not
properly released before returning.

So this patch add kfree() on the above error path to release it. As there
is no proper device to test with, no runtime testing was performed.

Signed-off-by: Xiaoke Wang <xkernel.wang@xxxxxxxxxxx>
---
ChangeLog:
v1->v2 update the description.
v2->v3 rebase.
v3->v4 update the description.
drivers/staging/r8188eu/os_dep/xmit_linux.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/os_dep/xmit_linux.c b/drivers/staging/r8188eu/os_dep/xmit_linux.c
index 89a598a..f25099d 100644
--- a/drivers/staging/r8188eu/os_dep/xmit_linux.c
+++ b/drivers/staging/r8188eu/os_dep/xmit_linux.c
@@ -75,8 +75,10 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitb
pxmitbuf->dma_transfer_addr = 0;
pxmitbuf->pxmit_urb = usb_alloc_urb(0, GFP_KERNEL);
- if (!pxmitbuf->pxmit_urb)
+ if (!pxmitbuf->pxmit_urb) {
+ kfree(pxmitbuf->pallocated_buf);
return _FAIL;
+ }
return _SUCCESS;
}

Hi,

I cannot apply your patch:

kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ cat ~/Downloads/\[PATCH\ v4\]\ staging\ r8188eu\ fix\ potential\ memory\ leak\ in\ rtw_os_xmit_resource_alloc\(\).eml | git am
Applying: staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()
error: drivers/staging/r8188eu/os_dep/xmit_linux.c: does not exist in index
Patch failed at 0001 staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()

branch: staging-next
repository: git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git

Sorry

Bye Philipp