[PATCH][next] staging: rtl8188eu: Fix null pointer dereference on free_netdev call

From: Colin King
Date: Wed Mar 24 2021 - 11:22:21 EST


From: Colin Ian King <colin.king@xxxxxxxxxxxxx>

An unregister_netdev call checks if pnetdev is null, hence a later
call to free_netdev can potentially be passing a null pointer, causing
a null pointer dereference. Avoid this by adding a null pointer check
on pnetdev before calling free_netdev.

Fixes: 1665c8fdffbb ("staging: rtl8188eu: use netdev routines for private data")
Signed-off-by: Colin Ian King <colin.king@xxxxxxxxxxxxx>
---
drivers/staging/rtl8188eu/os_dep/usb_intf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 518e9feb3f46..91a3d34a1050 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -446,7 +446,8 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
pr_debug("+r871xu_dev_remove, hw_init_completed=%d\n",
if1->hw_init_completed);
rtw_free_drv_sw(if1);
- free_netdev(pnetdev);
+ if (pnetdev)
+ free_netdev(pnetdev);
}

static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
--
2.30.2