From c597fa83da1df841739e769bdbb95a09ae8a76b7 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 12 Aug 2021 13:40:27 -0700 Subject: [PATCH] Reorganize error handling in rtw_drv_init() Looking at the error function as a whole, the error handling is odd compared to the rest of the kernel, which prefers to set error codes on goto paths, rather than a global "status" variable which determines the error code at the end of the function and function calls in the case of error. Rearrange the error handling of this function to bring it more inline with how the kernel does it in most cases, which helps readability. Link: https://lore.kernel.org/r/20210812204027.338872-4-nathan@kernel.org Link: https://lore.kernel.org/r/20210813201418.4018631-1-nathan@kernel.org --- os_dep/linux/usb_intf.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/os_dep/linux/usb_intf.c b/os_dep/linux/usb_intf.c index 0e9c628..37b6cee 100644 --- a/os_dep/linux/usb_intf.c +++ b/os_dep/linux/usb_intf.c @@ -1471,7 +1471,6 @@ static void rtw_usb_primary_adapter_deinit(_adapter *padapter) static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid) { _adapter *padapter = NULL; - int status = _FAIL; struct dvobj_priv *dvobj; #ifdef CONFIG_CONCURRENT_MODE int i; @@ -1484,8 +1483,8 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device /* Initialize dvobj_priv */ dvobj = usb_dvobj_init(pusb_intf, pdid); - if (dvobj == NULL) { - goto exit; + if (!dvobj) { + goto err; } padapter = rtw_usb_primary_adapter_init(dvobj, pusb_intf); @@ -1534,30 +1533,21 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device #endif - status = _SUCCESS; + return 0; -#if 0 /* not used now */ -os_ndevs_deinit: - if (status != _SUCCESS) - rtw_os_ndevs_deinit(dvobj); -#endif free_if_vir: - if (status != _SUCCESS) { - #ifdef CONFIG_CONCURRENT_MODE - rtw_drv_stop_vir_ifaces(dvobj); - rtw_drv_free_vir_ifaces(dvobj); - #endif - } + #ifdef CONFIG_CONCURRENT_MODE + rtw_drv_stop_vir_ifaces(dvobj); + rtw_drv_free_vir_ifaces(dvobj); + #endif free_if_prim: - if (status != _SUCCESS && padapter) - rtw_usb_primary_adapter_deinit(padapter); + rtw_usb_primary_adapter_deinit(padapter); free_dvobj: - if (status != _SUCCESS) - usb_dvobj_deinit(pusb_intf); -exit: - return status == _SUCCESS ? 0 : -ENODEV; + usb_dvobj_deinit(pusb_intf); +err: + return -ENODEV; } /*