* [PATCH] staging: r8188eu: change the allocation type of pdata_attr
@ 2022-03-31 7:37 xkernel.wang
2022-03-31 9:09 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-03-31 7:37 UTC (permalink / raw)
To: gregkh, dan.carpenter
Cc: Larry.Finger, phil, linux-staging, linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
`pdata_attr` was allocated by kzalloc() in go_add_group_info_attr(), but
there is a lack of error handlers along the call chain it lies and the
lifetime of `pdata_attr` is only in go_add_group_info_attr().
Therefore, changing it to a local variable on stack like the other
functions in rtw_p2p.c is a possible choice, such as
`u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };` in build_probe_resp_p2p_ie()
which is the caller of go_add_group_info_attr().
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
drivers/staging/r8188eu/core/rtw_p2p.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/r8188eu/core/rtw_p2p.c b/drivers/staging/r8188eu/core/rtw_p2p.c
index e2b6cf2..f1a5df8 100644
--- a/drivers/staging/r8188eu/core/rtw_p2p.c
+++ b/drivers/staging/r8188eu/core/rtw_p2p.c
@@ -27,15 +27,14 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
struct list_head *phead, *plist;
u32 len = 0;
u16 attr_len = 0;
- u8 tmplen, *pdata_attr, *pstart, *pcur;
+ u8 pdata_attr[MAX_P2P_IE_LEN] = { 0x00 };
+ u8 tmplen, *pstart, *pcur;
struct sta_info *psta = NULL;
struct adapter *padapter = pwdinfo->padapter;
struct sta_priv *pstapriv = &padapter->stapriv;
DBG_88E("%s\n", __func__);
- pdata_attr = kzalloc(MAX_P2P_IE_LEN, GFP_KERNEL);
-
pstart = pdata_attr;
pcur = pdata_attr;
@@ -106,7 +105,6 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
if (attr_len > 0)
len = rtw_set_p2p_attr_content(pbuf, P2P_ATTR_GROUP_INFO, attr_len, pdata_attr);
- kfree(pdata_attr);
return len;
}
--
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: r8188eu: change the allocation type of pdata_attr
2022-03-31 7:37 [PATCH] staging: r8188eu: change the allocation type of pdata_attr xkernel.wang
@ 2022-03-31 9:09 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2022-03-31 9:09 UTC (permalink / raw)
To: xkernel.wang
Cc: dan.carpenter, Larry.Finger, phil, linux-staging, linux-kernel
On Thu, Mar 31, 2022 at 03:37:00PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> `pdata_attr` was allocated by kzalloc() in go_add_group_info_attr(), but
> there is a lack of error handlers along the call chain it lies and the
> lifetime of `pdata_attr` is only in go_add_group_info_attr().
> Therefore, changing it to a local variable on stack like the other
> functions in rtw_p2p.c is a possible choice, such as
> `u8 p2pie[MAX_P2P_IE_LEN] = { 0x00 };` in build_probe_resp_p2p_ie()
> which is the caller of go_add_group_info_attr().
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> drivers/staging/r8188eu/core/rtw_p2p.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_p2p.c b/drivers/staging/r8188eu/core/rtw_p2p.c
> index e2b6cf2..f1a5df8 100644
> --- a/drivers/staging/r8188eu/core/rtw_p2p.c
> +++ b/drivers/staging/r8188eu/core/rtw_p2p.c
> @@ -27,15 +27,14 @@ static u32 go_add_group_info_attr(struct wifidirect_info *pwdinfo, u8 *pbuf)
> struct list_head *phead, *plist;
> u32 len = 0;
> u16 attr_len = 0;
> - u8 tmplen, *pdata_attr, *pstart, *pcur;
> + u8 pdata_attr[MAX_P2P_IE_LEN] = { 0x00 };
As I said before, this is way too big to put on the stack.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-31 9:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-31 7:37 [PATCH] staging: r8188eu: change the allocation type of pdata_attr xkernel.wang
2022-03-31 9:09 ` Greg KH
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).