Skip to content

Commit

Permalink
staging: rtl8712: fix a potential memory leak in r871xu_drv_init()
Browse files Browse the repository at this point in the history
In r871xu_drv_init(), if r8712_init_drv_sw() fails, then the memory
allocated by r8712_alloc_io_queue() in r8712_usb_dvobj_init() is not
properly released as there is no action will be performed by
r8712_usb_dvobj_deinit().
To properly release it, we should call r8712_free_io_queue() in
r8712_usb_dvobj_deinit().

Besides, in r871xu_dev_remove(), r8712_usb_dvobj_deinit() will be called
by r871x_dev_unload() under condition `padapter->bup` and
r8712_free_io_queue() is called by r8712_free_drv_sw().
However, r8712_usb_dvobj_deinit() does not rely on `padapter->bup` and
calling r8712_free_io_queue() in r8712_free_drv_sw() is negative for
better understading the code.
So I move r8712_usb_dvobj_deinit() into r871xu_dev_remove(), and remove
r8712_free_io_queue() from r8712_free_drv_sw().

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Link: https://lore.kernel.org/r/tencent_B8048C592777830380A23A7C4409F9DF1305@qq.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
x2018 authored and gregkh committed Apr 5, 2022
1 parent a461466 commit 7288ff5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion drivers/staging/rtl8712/os_intfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ void r8712_free_drv_sw(struct _adapter *padapter)
r8712_free_evt_priv(&padapter->evtpriv);
r8712_DeInitSwLeds(padapter);
r8712_free_mlme_priv(&padapter->mlmepriv);
r8712_free_io_queue(padapter);
_free_xmit_priv(&padapter->xmitpriv);
_r8712_free_sta_priv(&padapter->stapriv);
_r8712_free_recv_priv(&padapter->recvpriv);
Expand Down
6 changes: 3 additions & 3 deletions drivers/staging/rtl8712/usb_intf.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ static uint r8712_usb_dvobj_init(struct _adapter *padapter)

static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
{
r8712_free_io_queue(padapter);
}

void rtl871x_intf_stop(struct _adapter *padapter)
Expand Down Expand Up @@ -302,9 +303,6 @@ void r871x_dev_unload(struct _adapter *padapter)
rtl8712_hal_deinit(padapter);
}

/*s6.*/
if (padapter->dvobj_deinit)
padapter->dvobj_deinit(padapter);
padapter->bup = false;
}
}
Expand Down Expand Up @@ -607,6 +605,8 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf)
/* Stop driver mlme relation timer */
r8712_stop_drv_timers(padapter);
r871x_dev_unload(padapter);
if (padapter->dvobj_deinit)
padapter->dvobj_deinit(padapter);
r8712_free_drv_sw(padapter);
free_netdev(pnetdev);

Expand Down

0 comments on commit 7288ff5

Please sign in to comment.