Commit 0bd35146 authored by Nathan Chancellor's avatar Nathan Chancellor Committed by Greg Kroah-Hartman

staging: r8188eu: Reorganize error handling in rtw_drv_init()

After commit 987219ad ("staging: r8188eu: remove lines from Makefile
that silence build warnings"), clang warns:

drivers/staging/r8188eu/os_dep/usb_intf.c:726:6: warning: variable
'status' is used uninitialized whenever 'if' condition is true
[-Wsometimes-uninitialized]
        if (!if1) {
            ^~~~
drivers/staging/r8188eu/os_dep/usb_intf.c:741:6: note: uninitialized use
occurs here
        if (status != _SUCCESS)
            ^~~~~~
drivers/staging/r8188eu/os_dep/usb_intf.c:726:2: note: remove the 'if'
if its condition is always false
        if (!if1) {
        ^~~~~~~~~~~
drivers/staging/r8188eu/os_dep/usb_intf.c:714:12: note: initialize the
variable 'status' to silence this warning
        int status;
                  ^
                   = 0
1 warning generated.

status is not initialized if the call to usb_dvobj_init() or
rtw_usb_if1_init() fails.

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.

The call to rtw_usb_if1_deinit() is eliminated because it is not
possible to ever hit it; if rtw_usb_if1_init() fails, the goto call
jumps over the call to rtw_usb_if1_deinit() and in the success case,
status is set to _SUCCESS.
Acked-by: default avatarPhillip Potter <phil@philpotter.co.uk>
Acked-by: default avatarFabio M. De Francesco <fmdefrancesco@gmail.com>
Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
Link: https://lore.kernel.org/r/20210812204027.338872-4-nathan@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 72a5e1d7
...@@ -704,20 +704,23 @@ static void rtw_usb_if1_deinit(struct adapter *if1) ...@@ -704,20 +704,23 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid) static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
{ {
struct adapter *if1 = NULL; struct adapter *if1 = NULL;
int status;
struct dvobj_priv *dvobj; struct dvobj_priv *dvobj;
int ret;
/* step 0. */ /* step 0. */
process_spec_devid(pdid); process_spec_devid(pdid);
/* Initialize dvobj_priv */ /* Initialize dvobj_priv */
dvobj = usb_dvobj_init(pusb_intf); dvobj = usb_dvobj_init(pusb_intf);
if (!dvobj) if (!dvobj) {
goto exit; ret = -ENODEV;
goto err;
}
if1 = rtw_usb_if1_init(dvobj, pusb_intf); if1 = rtw_usb_if1_init(dvobj, pusb_intf);
if (!if1) { if (!if1) {
DBG_88E("rtw_init_primarystruct adapter Failed!\n"); DBG_88E("rtw_init_primarystruct adapter Failed!\n");
ret = -ENODEV;
goto free_dvobj; goto free_dvobj;
} }
...@@ -726,15 +729,12 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device ...@@ -726,15 +729,12 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device
rtw_signal_process(ui_pid[1], SIGUSR2); rtw_signal_process(ui_pid[1], SIGUSR2);
} }
status = _SUCCESS; return 0;
if (status != _SUCCESS && if1)
rtw_usb_if1_deinit(if1);
free_dvobj: free_dvobj:
if (status != _SUCCESS)
usb_dvobj_deinit(pusb_intf); usb_dvobj_deinit(pusb_intf);
exit: err:
return status == _SUCCESS ? 0 : -ENODEV; return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment