Skip to content

Commit 1868755

Browse files
MakwanaVihasgregkh
authored andcommitted
staging: r8188eu: proper error handling in rtw_init_drv_sw
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 _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. Fixes: 2b42bd5 ("staging: r8188eu: introduce new os_dep dir for RTL8188eu driver") Reviewed-by: Dan Carpenter <[email protected]> Reviewed-by: Pavel Skripkin <[email protected]> Signed-off-by: Vihas Makwana <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 57a42b4 commit 1868755

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

drivers/staging/r8188eu/os_dep/os_intfs.c

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,32 +469,46 @@ u8 rtw_reset_drv_sw(struct adapter *padapter)
469469

470470
u8 rtw_init_drv_sw(struct adapter *padapter)
471471
{
472-
if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL)
472+
if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
473+
dev_err(dvobj_to_dev(padapter->dvobj), "rtw_init_cmd_priv failed\n");
473474
return _FAIL;
475+
}
474476

475477
padapter->cmdpriv.padapter = padapter;
476478

477-
if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL)
478-
return _FAIL;
479+
if ((rtw_init_evt_priv(&padapter->evtpriv)) == _FAIL) {
480+
dev_err(dvobj_to_dev(padapter->dvobj), "rtw_init_evt_priv failed\n");
481+
goto free_cmd_priv;
482+
}
479483

480-
if (rtw_init_mlme_priv(padapter) == _FAIL)
481-
return _FAIL;
484+
if (rtw_init_mlme_priv(padapter) == _FAIL) {
485+
dev_err(dvobj_to_dev(padapter->dvobj), "rtw_init_mlme_priv failed\n");
486+
goto free_evt_priv;
487+
}
482488

483489
rtw_init_wifidirect_timers(padapter);
484490
init_wifidirect_info(padapter, P2P_ROLE_DISABLE);
485491
reset_global_wifidirect_info(padapter);
486492

487-
if (init_mlme_ext_priv(padapter) == _FAIL)
488-
return _FAIL;
493+
if (init_mlme_ext_priv(padapter) == _FAIL) {
494+
dev_err(dvobj_to_dev(padapter->dvobj), "init_mlme_ext_priv failed\n");
495+
goto free_mlme_priv;
496+
}
489497

490-
if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL)
491-
return _FAIL;
498+
if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
499+
dev_err(dvobj_to_dev(padapter->dvobj), "_rtw_init_xmit_priv failed\n");
500+
goto free_mlme_ext;
501+
}
492502

493-
if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL)
494-
return _FAIL;
503+
if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
504+
dev_err(dvobj_to_dev(padapter->dvobj), "_rtw_init_recv_priv failed\n");
505+
goto free_xmit_priv;
506+
}
495507

496-
if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL)
497-
return _FAIL;
508+
if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
509+
dev_err(dvobj_to_dev(padapter->dvobj), "_rtw_init_sta_priv failed\n");
510+
goto free_recv_priv;
511+
}
498512

499513
padapter->stapriv.padapter = padapter;
500514

@@ -510,6 +524,26 @@ u8 rtw_init_drv_sw(struct adapter *padapter)
510524
spin_lock_init(&padapter->br_ext_lock);
511525

512526
return _SUCCESS;
527+
528+
free_recv_priv:
529+
_rtw_free_recv_priv(&padapter->recvpriv);
530+
531+
free_xmit_priv:
532+
_rtw_free_xmit_priv(&padapter->xmitpriv);
533+
534+
free_mlme_ext:
535+
free_mlme_ext_priv(&padapter->mlmeextpriv);
536+
537+
free_mlme_priv:
538+
rtw_free_mlme_priv(&padapter->mlmepriv);
539+
540+
free_evt_priv:
541+
rtw_free_evt_priv(&padapter->evtpriv);
542+
543+
free_cmd_priv:
544+
rtw_free_cmd_priv(&padapter->cmdpriv);
545+
546+
return _FAIL;
513547
}
514548

515549
void rtw_cancel_all_timer(struct adapter *padapter)

0 commit comments

Comments
 (0)