public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: add kfree() on an error path of rtw_xmit_resource_alloc()
@ 2022-09-10  0:29 xkernel.wang
  2022-09-10  6:29 ` Philipp Hortmann
  0 siblings, 1 reply; 3+ messages in thread
From: xkernel.wang @ 2022-09-10  0:29 UTC (permalink / raw)
  To: Larry.Finger, phil, gregkh, philipp.g.hortmann
  Cc: linux-staging, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

In rtw_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 adds 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@foxmail.com>
---
 drivers/staging/r8188eu/core/rtw_xmit.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
index 67f9c05..9c39d08 100644
--- a/drivers/staging/r8188eu/core/rtw_xmit.c
+++ b/drivers/staging/r8188eu/core/rtw_xmit.c
@@ -44,8 +44,10 @@ static int rtw_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *px
 	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;
 }
-- 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: r8188eu: add kfree() on an error path of rtw_xmit_resource_alloc()
  2022-09-10  0:29 [PATCH] staging: r8188eu: add kfree() on an error path of rtw_xmit_resource_alloc() xkernel.wang
@ 2022-09-10  6:29 ` Philipp Hortmann
  2022-09-11 11:59   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Philipp Hortmann @ 2022-09-10  6:29 UTC (permalink / raw)
  To: xkernel.wang, Larry.Finger, phil, gregkh; +Cc: linux-staging, linux-kernel

On 9/10/22 02:29, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> In rtw_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 adds 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@foxmail.com>
> ---
>   drivers/staging/r8188eu/core/rtw_xmit.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
> index 67f9c05..9c39d08 100644
> --- a/drivers/staging/r8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/r8188eu/core/rtw_xmit.c
> @@ -44,8 +44,10 @@ static int rtw_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *px
>   	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 Xiaoke,

I applied your patch and tested it. That is OK.

But you excluded the change history. Usually this is not accepted by 
Greg. Reason is that what identifies the patch is the change itself. The 
change itself is the same as: "[PATCH v4] staging: r8188eu: fix 
potential memory leak in rtw_os_xmit_resource_alloc()" Even if you 
change the Subject, Description and the branch it remains the same patch 
for Greg.

Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com> # Edimax N150


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: r8188eu: add kfree() on an error path of rtw_xmit_resource_alloc()
  2022-09-10  6:29 ` Philipp Hortmann
@ 2022-09-11 11:59   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2022-09-11 11:59 UTC (permalink / raw)
  To: Philipp Hortmann, xkernel.wang, Larry.Finger, phil, linux-staging,
	linux-kernel

On Sat, Sep 10, 2022 at 08:29:03AM +0200, Philipp Hortmann wrote:
> On 9/10/22 02:29, xkernel.wang@foxmail.com wrote:
> > From: Xiaoke Wang <xkernel.wang@foxmail.com>
> > 
> > In rtw_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 adds 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@foxmail.com>
> > ---
> >   drivers/staging/r8188eu/core/rtw_xmit.c | 4 +++-
> >   1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/staging/r8188eu/core/rtw_xmit.c b/drivers/staging/r8188eu/core/rtw_xmit.c
> > index 67f9c05..9c39d08 100644
> > --- a/drivers/staging/r8188eu/core/rtw_xmit.c
> > +++ b/drivers/staging/r8188eu/core/rtw_xmit.c
> > @@ -44,8 +44,10 @@ static int rtw_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *px
> >   	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 Xiaoke,
> 
> I applied your patch and tested it. That is OK.
> 
> But you excluded the change history. Usually this is not accepted by Greg.
> Reason is that what identifies the patch is the change itself. The change
> itself is the same as: "[PATCH v4] staging: r8188eu: fix potential memory
> leak in rtw_os_xmit_resource_alloc()" Even if you change the Subject,
> Description and the branch it remains the same patch for Greg.

Agreed, please fix up.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-11 11:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-10  0:29 [PATCH] staging: r8188eu: add kfree() on an error path of rtw_xmit_resource_alloc() xkernel.wang
2022-09-10  6:29 ` Philipp Hortmann
2022-09-11 11:59   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox