* [PATCH] staging: r8188eu: fix a potential memory leak in _rtw_init_cmd_priv()
@ 2022-03-30 11:32 xkernel.wang
2022-03-30 11:43 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: xkernel.wang @ 2022-03-30 11:32 UTC (permalink / raw)
To: Larry.Finger, phil, gregkh; +Cc: linux-staging, linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
In _rtw_init_cmd_priv(), if `pcmdpriv->rsp_allocated_buf` is allocated
in failure, `pcmdpriv->cmd_allocated_buf` is not properly released.
This patch is to free it.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
drivers/staging/r8188eu/core/rtw_cmd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
index 56910c3..e76015e 100644
--- a/drivers/staging/r8188eu/core/rtw_cmd.c
+++ b/drivers/staging/r8188eu/core/rtw_cmd.c
@@ -42,6 +42,8 @@ static int _rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
pcmdpriv->rsp_allocated_buf = kzalloc(MAX_RSPSZ + 4, GFP_KERNEL);
if (!pcmdpriv->rsp_allocated_buf) {
+ kfree(pcmdpriv->cmd_allocated_buf);
+ pcmdpriv->cmd_allocated_buf = NULL;
res = _FAIL;
goto exit;
}
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: r8188eu: fix a potential memory leak in _rtw_init_cmd_priv()
2022-03-30 11:32 [PATCH] staging: r8188eu: fix a potential memory leak in _rtw_init_cmd_priv() xkernel.wang
@ 2022-03-30 11:43 ` Greg KH
2022-03-30 12:14 ` Xiaoke Wang
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2022-03-30 11:43 UTC (permalink / raw)
To: xkernel.wang; +Cc: Larry.Finger, phil, linux-staging, linux-kernel
On Wed, Mar 30, 2022 at 07:32:21PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> In _rtw_init_cmd_priv(), if `pcmdpriv->rsp_allocated_buf` is allocated
> in failure, `pcmdpriv->cmd_allocated_buf` is not properly released.
> This patch is to free it.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> drivers/staging/r8188eu/core/rtw_cmd.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
> index 56910c3..e76015e 100644
> --- a/drivers/staging/r8188eu/core/rtw_cmd.c
> +++ b/drivers/staging/r8188eu/core/rtw_cmd.c
> @@ -42,6 +42,8 @@ static int _rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
> pcmdpriv->rsp_allocated_buf = kzalloc(MAX_RSPSZ + 4, GFP_KERNEL);
>
> if (!pcmdpriv->rsp_allocated_buf) {
> + kfree(pcmdpriv->cmd_allocated_buf);
> + pcmdpriv->cmd_allocated_buf = NULL;
> res = _FAIL;
> goto exit;
Shouldn't this be handled properly in the exit: portion instead?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Re: [PATCH] staging: r8188eu: fix a potential memory leak in _rtw_init_cmd_priv()
2022-03-30 11:43 ` Greg KH
@ 2022-03-30 12:14 ` Xiaoke Wang
0 siblings, 0 replies; 3+ messages in thread
From: Xiaoke Wang @ 2022-03-30 12:14 UTC (permalink / raw)
To: gregkh; +Cc: Larry.Finger, phil, linux-staging, linux-kernel
On Wed, 30 Mar 2022 19:43:40 +0800, gregkh@linuxfoundation.org wrote:
>> if (!pcmdpriv->rsp_allocated_buf) {
>> + kfree(pcmdpriv->cmd_allocated_buf);
>> + pcmdpriv->cmd_allocated_buf = NULL;
>> res = _FAIL;
>> goto exit;
>Shouldn't this be handled properly in the exit: portion instead?
I think this is ok since we do not need to free it in normal exit.
But if you like that, I can add an err label and move the operations
to there.
Or maybe we can directly return the status rather than changing
`res` since there are only two possibilities.
Regards,
Xiaoke Wang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-30 12:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-30 11:32 [PATCH] staging: r8188eu: fix a potential memory leak in _rtw_init_cmd_priv() xkernel.wang
2022-03-30 11:43 ` Greg KH
2022-03-30 12:14 ` Xiaoke Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).