Commit 5a5aa9cc authored by Xiaoke Wang's avatar Xiaoke Wang Committed by Greg Kroah-Hartman

staging: rtl8723bs: fix potential memory leak in rtw_init_drv_sw()

In rtw_init_drv_sw(), there are various init functions are called to
populate the padapter structure and some checks for their return value.
However, except for the first one error path, the other five error paths
do not properly release the previous allocated resources, which leads to
various memory leaks.

This patch fixes them and keeps the success and error separate.
Note that these changes keep the form of `rtw_init_drv_sw()` in
"drivers/staging/r8188eu/os_dep/os_intfs.c". As there is no proper device
to test with, no runtime testing was performed.
Signed-off-by: default avatarXiaoke Wang <xkernel.wang@foxmail.com>
Link: https://lore.kernel.org/r/tencent_C3B899D2FC3F1BC827F3552E0B0734056006@qq.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9bbf2f32
......@@ -664,51 +664,36 @@ void rtw_reset_drv_sw(struct adapter *padapter)
u8 rtw_init_drv_sw(struct adapter *padapter)
{
u8 ret8 = _SUCCESS;
rtw_init_default_value(padapter);
rtw_init_hal_com_default_value(padapter);
if (rtw_init_cmd_priv(&padapter->cmdpriv)) {
ret8 = _FAIL;
goto exit;
}
if (rtw_init_cmd_priv(&padapter->cmdpriv))
return _FAIL;
padapter->cmdpriv.padapter = padapter;
if (rtw_init_evt_priv(&padapter->evtpriv)) {
ret8 = _FAIL;
goto exit;
}
if (rtw_init_evt_priv(&padapter->evtpriv))
goto free_cmd_priv;
if (rtw_init_mlme_priv(padapter) == _FAIL) {
ret8 = _FAIL;
goto exit;
}
if (rtw_init_mlme_priv(padapter) == _FAIL)
goto free_evt_priv;
init_mlme_ext_priv(padapter);
if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
ret8 = _FAIL;
goto exit;
}
if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL)
goto free_mlme_ext;
if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
ret8 = _FAIL;
goto exit;
}
if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL)
goto free_xmit_priv;
/* add for CONFIG_IEEE80211W, none 11w also can use */
spin_lock_init(&padapter->security_key_mutex);
/* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
/* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */
if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
ret8 = _FAIL;
goto exit;
}
if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL)
goto free_recv_priv;
padapter->stapriv.padapter = padapter;
padapter->setband = GHZ24_50;
......@@ -719,9 +704,26 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
rtw_hal_dm_init(padapter);
exit:
return _SUCCESS;
free_recv_priv:
_rtw_free_recv_priv(&padapter->recvpriv);
free_xmit_priv:
_rtw_free_xmit_priv(&padapter->xmitpriv);
free_mlme_ext:
free_mlme_ext_priv(&padapter->mlmeextpriv);
return ret8;
rtw_free_mlme_priv(&padapter->mlmepriv);
free_evt_priv:
rtw_free_evt_priv(&padapter->evtpriv);
free_cmd_priv:
rtw_free_cmd_priv(&padapter->cmdpriv);
return _FAIL;
}
void rtw_cancel_all_timer(struct adapter *padapter)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment