staging: r8188eu: improve error handling
v2 cover staging: r8188eu: improve error handling
This patchset improves error handling in rtw_init_drv_sw() and fixes some memory leaks.
v1->v2:
Added fixes tag in patch 2/2.
Used dev_err instead of pr_err as it prefixes the error with device info.
Vihas Makwana (2):
staging: r8188eu: call rtl8188eu_free_recv_priv from
_rtw_free_recv_priv
staging: r8188eu: proper error handling in rtw_init_drv_sw
drivers/staging/r8188eu/core/rtw_recv.c | 1 + drivers/staging/r8188eu/os_dep/os_intfs.c | 60 ++++++++++++++++++----- 2 files changed, 48 insertions(+), 13 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/2 staging: r8188eu: call _cancel_timer_ex from _rtw_free_recv_priv
The _rtw_init_recv_priv() initializes precvpriv->signal_stat_timer and sets it's timeout interval to 1000 ms. But _rtw_free_recv_priv() doesn't cancel the timer and we need to explicitly call _cancel_timer_ex() after we call _rtw_free_recv_priv() to cancel the timer.
Call _cancel_timer_ex() from inside _rtw_free_recv_priv() as every init function needs a matching free function.
--- drivers/staging/r8188eu/core/rtw_recv.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/r8188eu/core/rtw_recv.c +1 -0
@@ -103,6 +103,7 @@ void _rtw_free_recv_priv(struct recv_priv *precvpriv)vfree (precvpriv->pallocated_frame_buf);rtl8188eu_free_recv_priv (padapter); +_cancel_timer_ex (&precvpriv->signal_stat_timer); }struct recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue)
Signature · 1 line
2.30.2
PATCH v2 2/2 staging: r8188eu: proper error handling in rtw_init_drv_sw
In reply to Vihas MakwanaThe code inside rtw_init_drv_sw() calls various init functions to populate the padapter structure and checks for their return values respectively.
But if one of the functions in middle fails then it simply returns _FAIL instead of proper logging and calling freeing counterparts of previous init functions.
This leads to various memory leaks and can be found in /sys/kernel/debug/kmemleak if kernel is compiled with DEBUG_KMEMLEAK=y.
Fix this and keep the success and error separate.
RTL8188eu driver")
---
Tested on Comfast CF-WU810N RTL8188EUS wireless adapter.
--- drivers/staging/r8188eu/os_dep/os_intfs.c | 60 ++++++++++++++++++----- 1 file changed, 47 insertions(+), 13 deletions(-)
drivers/staging/r8188eu/os_dep/os_intfs.c +47 -13
@@ -469,32 +469,46 @@ u8 rtw_reset_drv_sw(struct adapter *padapter)u8 rtw_init_drv_sw (struct adapter *padapter) { -if ((rtw_init_cmd_priv (&padapter->cmdpriv)) == _FAIL) +if ((rtw_init_cmd_priv (&padapter->cmdpriv)) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"rtw_init_cmd_priv failed\n" );return _FAIL; + } padapter->cmdpriv.padapter = padapter; -if ((rtw_init_evt_priv (&padapter->evtpriv)) == _FAIL) -return _FAIL; +if ((rtw_init_evt_priv (&padapter->evtpriv)) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"rtw_init_evt_priv failed\n" ); + goto free_cmd_priv; + } -if (rtw_init_mlme_priv (padapter) == _FAIL) -return _FAIL; +if (rtw_init_mlme_priv (padapter) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"rtw_init_mlme_priv failed\n" ); + goto free_evt_priv; + }rtw_init_wifidirect_timers (padapter);init_wifidirect_info (padapter,P2P_ROLE_DISABLE );reset_global_wifidirect_info (padapter); -if (init_mlme_ext_priv (padapter) == _FAIL) -return _FAIL; +if (init_mlme_ext_priv (padapter) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"init_mlme_ext_priv failed\n" ); + goto free_mlme_priv; + } -if (_rtw_init_xmit_priv (&padapter->xmitpriv, padapter) == _FAIL) -return _FAIL; +if (_rtw_init_xmit_priv (&padapter->xmitpriv, padapter) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"_rtw_init_xmit_priv failed\n" ); + goto free_mlme_ext; + } -if (_rtw_init_recv_priv (&padapter->recvpriv, padapter) == _FAIL) -return _FAIL; +if (_rtw_init_recv_priv (&padapter->recvpriv, padapter) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"_rtw_init_recv_priv failed\n" ); + goto free_xmit_priv; + } -if (_rtw_init_sta_priv (&padapter->stapriv) == _FAIL) -return _FAIL; +if (_rtw_init_sta_priv (&padapter->stapriv) == _FAIL) { +dev_err (dvobj_to_dev (padapter->dvobj),"_rtw_init_sta_priv failed\n" ); + goto free_recv_priv; + } padapter->stapriv.padapter = padapter;
@@ -510,6 +524,26 @@ u8 rtw_init_drv_sw(struct adapter *padapter)spin_lock_init (&padapter->br_ext_lock);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); + +free_mlme_priv: +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)
Signature · 1 line
2.30.2
Greg Kroah-Hartman
maintainerRe: [PATCH v2 2/2] staging: r8188eu: proper error handling in rtw_init_drv_sw
Quoted 9 lines · Vihas Makwana
The code inside
rtw_init_drv_sw()calls various init functions to populate the padapter structure and checks for their return values respectively.
But if one of the functions in middle fails then it simply returns_FAILinstead of proper logging and calling freeing counterparts of previous init functions.
This leads to various memory leaks and can be found in/sys/kernel/debug/kmemleakif kernel is compiled with DEBUG_KMEMLEAK=y.
Quoted 4 lines
Fix this and keep the success and error separate.
Fixes 2b42bd58b321 ("staging: r8188eu: introduce new os_dep dir forRTL8188eu driver")
Nit, that needed to be on one line, and no blank line before the next ones.
I've fixed it up now.
thanks,
greg k-h
Re: [PATCH v2 2/2] staging: r8188eu: proper error handling in rtw_init_drv_sw
Quoted 10 lines · Vihas Makwana
Quoted 9 lines
The code inside
rtw_init_drv_sw()calls various init functions to populate the padapter structure and checks for their return values respectively.
But if one of the functions in middle fails then it simply returns_FAILinstead of proper logging and calling freeing counterparts of previous init functions.
This leads to various memory leaks and can be found in/sys/kernel/debug/kmemleakif kernel is compiled with DEBUG_KMEMLEAK=y.
Quoted 8 lines
Quoted 4 lines
Fix this and keep the success and error separate.
Fixes 2b42bd58b321 ("staging: r8188eu: introduce new os_dep dir forRTL8188eu driver")
Nit, that needed to be on one line, and no blank line before the next ones.
Oh okay. I will take care of that when submitting patches in future.
Quoted 2 lines
I've fixed it up now.
Thanks Greg.
Quoted 24 lines · Greg Kroah-Hartman
Quoted 9 lines · Vihas Makwana
The code inside
rtw_init_drv_sw()calls various init functions to populate the padapter structure and checks for their return values respectively.
But if one of the functions in middle fails then it simply returns_FAILinstead of proper logging and calling freeing counterparts of previous init functions.
This leads to various memory leaks and can be found in/sys/kernel/debug/kmemleakif kernel is compiled with DEBUG_KMEMLEAK=y.Quoted 4 lines
Fix this and keep the success and error separate.
Fixes 2b42bd58b321 ("staging: r8188eu: introduce new os_dep dir forRTL8188eu driver")
Nit, that needed to be on one line, and no blank line before the next ones.
I've fixed it up now.
thanks,
greg k-h
Signature · 2 lines
Thanks, Vihas