staging: vt6656: clean-up registers initialization error path
authorQuentin Deslandes <quentin.deslandes@itdev.co.uk>
Mon, 20 May 2019 16:39:04 +0000 (16:39 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 21 May 2019 06:25:04 +0000 (08:25 +0200)
Avoid discarding function's return code during register initialization.
Handle it instead and return 0 on success or a negative errno value on
error.

Signed-off-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vt6656/main_usb.c

index 5fd845cbdd529ef5fe3d729729e2e04dc33d8d57..8ed96e8eedbe9a20e5216a979a9f86034968f995 100644 (file)
@@ -109,33 +109,38 @@ static void vnt_set_options(struct vnt_private *priv)
  */
 static int vnt_init_registers(struct vnt_private *priv)
 {
+       int ret = 0;
        struct vnt_cmd_card_init *init_cmd = &priv->init_command;
        struct vnt_rsp_card_init *init_rsp = &priv->init_response;
        u8 antenna;
        int ii;
-       int status = STATUS_SUCCESS;
        u8 tmp;
        u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
 
        dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
                DEVICE_INIT_COLD, priv->packet_type);
 
-       if (!vnt_check_firmware_version(priv)) {
-               if (vnt_download_firmware(priv) == true) {
-                       if (vnt_firmware_branch_to_sram(priv) == false) {
-                               dev_dbg(&priv->usb->dev,
-                                       " vnt_firmware_branch_to_sram fail\n");
-                               return false;
-                       }
-               } else {
-                       dev_dbg(&priv->usb->dev, "FIRMWAREbDownload fail\n");
-                       return false;
+       ret = vnt_check_firmware_version(priv);
+       if (ret) {
+               ret = vnt_download_firmware(priv);
+               if (ret) {
+                       dev_dbg(&priv->usb->dev,
+                               "Could not download firmware: %d.\n", ret);
+                       goto end;
+               }
+
+               ret = vnt_firmware_branch_to_sram(priv);
+               if (ret) {
+                       dev_dbg(&priv->usb->dev,
+                               "Could not branch to SRAM: %d.\n", ret);
+                       goto end;
                }
        }
 
-       if (!vnt_vt3184_init(priv)) {
+       ret = vnt_vt3184_init(priv);
+       if (ret) {
                dev_dbg(&priv->usb->dev, "vnt_vt3184_init fail\n");
-               return false;
+               goto end;
        }
 
        init_cmd->init_class = DEVICE_INIT_COLD;
@@ -146,28 +151,27 @@ static int vnt_init_registers(struct vnt_private *priv)
        init_cmd->long_retry_limit = priv->long_retry_limit;
 
        /* issue card_init command to device */
-       status = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
-                                sizeof(struct vnt_cmd_card_init),
-                                (u8 *)init_cmd);
-       if (status != STATUS_SUCCESS) {
+       ret = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
+                             sizeof(struct vnt_cmd_card_init),
+                             (u8 *)init_cmd);
+       if (ret) {
                dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
-               return false;
+               goto end;
        }
 
-       status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
-                               sizeof(struct vnt_rsp_card_init),
-                               (u8 *)init_rsp);
-       if (status != STATUS_SUCCESS) {
-               dev_dbg(&priv->usb->dev,
-                       "Cardinit request in status fail!\n");
-               return false;
+       ret = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
+                            sizeof(struct vnt_rsp_card_init),
+                            (u8 *)init_rsp);
+       if (ret) {
+               dev_dbg(&priv->usb->dev, "Cardinit request in status fail!\n");
+               goto end;
        }
 
        /* local ID for AES functions */
-       status = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
-                               MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
-       if (status != STATUS_SUCCESS)
-               return false;
+       ret = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
+                            MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
+       if (ret)
+               goto end;
 
        /* do MACbSoftwareReset in MACvInitialize */
 
@@ -253,7 +257,9 @@ static int vnt_init_registers(struct vnt_private *priv)
        }
 
        /* Set initial antenna mode */
-       vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
+       ret = vnt_set_antenna_mode(priv, priv->rx_antenna_mode);
+       if (ret)
+               goto end;
 
        /* get Auto Fall Back type */
        priv->auto_fb_ctrl = AUTO_FB_0;
@@ -275,33 +281,41 @@ static int vnt_init_registers(struct vnt_private *priv)
                                /* CR255, enable TX/RX IQ and
                                 * DC compensation mode
                                 */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xff,
-                                                  0x03);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xff, 0x03);
+                               if (ret)
+                                       goto end;
+
                                /* CR251, TX I/Q Imbalance Calibration */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xfb,
-                                                  calib_tx_iq);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xfb, calib_tx_iq);
+                               if (ret)
+                                       goto end;
+
                                /* CR252, TX DC-Offset Calibration */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xfC,
-                                                  calib_tx_dc);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xfC, calib_tx_dc);
+                               if (ret)
+                                       goto end;
+
                                /* CR253, RX I/Q Imbalance Calibration */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xfd,
-                                                  calib_rx_iq);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xfd, calib_rx_iq);
+                               if (ret)
+                                       goto end;
                        } else {
                                /* CR255, turn off
                                 * BB Calibration compensation
                                 */
-                               vnt_control_out_u8(priv,
-                                                  MESSAGE_REQUEST_BBREG,
-                                                  0xff,
-                                                  0x0);
+                               ret = vnt_control_out_u8(priv,
+                                                        MESSAGE_REQUEST_BBREG,
+                                                        0xff, 0x0);
+                               if (ret)
+                                       goto end;
                        }
                }
        }
@@ -323,37 +337,52 @@ static int vnt_init_registers(struct vnt_private *priv)
        else
                priv->short_slot_time = false;
 
-       vnt_set_short_slot_time(priv);
+       ret = vnt_set_short_slot_time(priv);
+       if (ret)
+               goto end;
 
        priv->radio_ctl = priv->eeprom[EEP_OFS_RADIOCTL];
 
        if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
-               status = vnt_control_in(priv, MESSAGE_TYPE_READ,
-                                       MAC_REG_GPIOCTL1,
-                                       MESSAGE_REQUEST_MACREG, 1, &tmp);
+               ret = vnt_control_in(priv, MESSAGE_TYPE_READ,
+                                    MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG,
+                                    1, &tmp);
+               if (ret)
+                       goto end;
 
-               if (status != STATUS_SUCCESS)
-                       return false;
+               if ((tmp & GPIO3_DATA) == 0) {
+                       ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
+                                                 GPIO3_INTMD);
+               } else {
+                       ret = vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
+                                                  GPIO3_INTMD);
+               }
 
-               if ((tmp & GPIO3_DATA) == 0)
-                       vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
-                                           GPIO3_INTMD);
-               else
-                       vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
-                                            GPIO3_INTMD);
+               if (ret)
+                       goto end;
        }
 
-       vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
 
-       vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
+       ret = vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
+       if (ret)
+               goto end;
 
-       vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
+       ret = vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
+       if (ret)
+               goto end;
 
-       vnt_radio_power_on(priv);
+       ret = vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL0, 0x01);
+       if (ret)
+               goto end;
+
+       ret = vnt_radio_power_on(priv);
+       if (ret)
+               goto end;
 
        dev_dbg(&priv->usb->dev, "<----INIbInitAdapter Exit\n");
 
-       return true;
+end:
+       return ret;
 }
 
 static void vnt_free_tx_bufs(struct vnt_private *priv)