suffix);
 }
 
+static int btusb_download_wait(struct hci_dev *hdev, ktime_t calltime, int msec)
+{
+       struct btusb_data *data = hci_get_drvdata(hdev);
+       ktime_t delta, rettime;
+       unsigned long long duration;
+       int err;
+
+       set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
+
+       bt_dev_info(hdev, "Waiting for firmware download to complete");
+
+       err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING,
+                                 TASK_INTERRUPTIBLE,
+                                 msecs_to_jiffies(msec));
+       if (err == -EINTR) {
+               bt_dev_err(hdev, "Firmware loading interrupted");
+               return err;
+       }
+
+       if (err) {
+               bt_dev_err(hdev, "Firmware loading timeout");
+               return -ETIMEDOUT;
+       }
+
+       if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
+               bt_dev_err(hdev, "Firmware loading failed");
+               return -ENOEXEC;
+       }
+
+       rettime = ktime_get();
+       delta = ktime_sub(rettime, calltime);
+       duration = (unsigned long long)ktime_to_ns(delta) >> 10;
+
+       bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
+
+       return 0;
+}
+
 static int btusb_intel_download_firmware_newgen(struct hci_dev *hdev,
                                                struct intel_version_tlv *ver,
                                                u32 *boot_param)
        char fwname[64];
        int err;
        struct btusb_data *data = hci_get_drvdata(hdev);
+       ktime_t calltime;
 
        if (!ver || !boot_param)
                return -EINVAL;
                goto done;
        }
 
+       calltime = ktime_get();
+
        set_bit(BTUSB_DOWNLOADING, &data->flags);
 
        /* Start firmware downloading and get boot parameter */
                btintel_reset_to_bootloader(hdev);
                goto done;
        }
-       set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
-
-       bt_dev_info(hdev, "Waiting for firmware download to complete");
 
        /* Before switching the device into operational mode and with that
         * booting the loaded firmware, wait for the bootloader notification
         * and thus just timeout if that happens and fail the setup
         * of this device.
         */
-       err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING,
-                                 TASK_INTERRUPTIBLE,
-                                 msecs_to_jiffies(5000));
-       if (err == -EINTR) {
-               bt_dev_err(hdev, "Firmware loading interrupted");
-               goto done;
-       }
-
-       if (err) {
-               bt_dev_err(hdev, "Firmware loading timeout");
-               err = -ETIMEDOUT;
+       err = btusb_download_wait(hdev, calltime, 5000);
+       if (err == -ETIMEDOUT)
                btintel_reset_to_bootloader(hdev);
-               goto done;
-       }
-
-       if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
-               bt_dev_err(hdev, "Firmware loading failed");
-               err = -ENOEXEC;
-               goto done;
-       }
 
 done:
        release_firmware(fw);
        char fwname[64];
        int err;
        struct btusb_data *data = hci_get_drvdata(hdev);
+       ktime_t calltime;
 
        if (!ver || !params)
                return -EINVAL;
                goto done;
        }
 
+       calltime = ktime_get();
+
        set_bit(BTUSB_DOWNLOADING, &data->flags);
 
        /* Start firmware downloading and get boot parameter */
                btintel_reset_to_bootloader(hdev);
                goto done;
        }
-       set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
-
-       bt_dev_info(hdev, "Waiting for firmware download to complete");
 
        /* Before switching the device into operational mode and with that
         * booting the loaded firmware, wait for the bootloader notification
         * and thus just timeout if that happens and fail the setup
         * of this device.
         */
-       err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING,
-                                 TASK_INTERRUPTIBLE,
-                                 msecs_to_jiffies(5000));
-       if (err == -EINTR) {
-               bt_dev_err(hdev, "Firmware loading interrupted");
-               goto done;
-       }
-
-       if (err) {
-               bt_dev_err(hdev, "Firmware loading timeout");
-               err = -ETIMEDOUT;
+       err = btusb_download_wait(hdev, calltime, 5000);
+       if (err == -ETIMEDOUT)
                btintel_reset_to_bootloader(hdev);
-               goto done;
-       }
-
-       if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
-               bt_dev_err(hdev, "Firmware loading failed");
-               err = -ENOEXEC;
-               goto done;
-       }
 
 done:
        release_firmware(fw);
         */
        boot_param = 0x00000000;
 
-       calltime = ktime_get();
-
        /* Read the Intel version information to determine if the device
         * is in bootloader mode or if it already has operational firmware
         * loaded.
        if (ver.fw_variant == 0x23)
                goto finish;
 
-       rettime = ktime_get();
-       delta = ktime_sub(rettime, calltime);
-       duration = (unsigned long long) ktime_to_ns(delta) >> 10;
-
-       bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
-
        calltime = ktime_get();
 
        set_bit(BTUSB_BOOTING, &data->flags);
         */
        boot_param = 0x00000000;
 
-       calltime = ktime_get();
-
        /* Read the Intel version information to determine if the device
         * is in bootloader mode or if it already has operational firmware
         * loaded.
        if (version.img_type == 0x03)
                goto finish;
 
-       rettime = ktime_get();
-       delta = ktime_sub(rettime, calltime);
-       duration = (unsigned long long)ktime_to_ns(delta) >> 10;
-
-       bt_dev_info(hdev, "Firmware loaded in %llu usecs", duration);
-
        calltime = ktime_get();
 
        set_bit(BTUSB_BOOTING, &data->flags);