drivers: USB Blaster II: close file and release USB device if firmware handling failed

In case of some error, the USB device and firmware file are still
claimed. Make sure refcounting is properly accounted for both cases.

Change-Id: I933114f68e59280e58372c0941a0062fe96ab340
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/6115
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
Oleksij Rempel 2021-03-18 18:47:35 +01:00 committed by Antonio Borneo
parent 08c7b904c3
commit f09aa77c0c
1 changed files with 5 additions and 3 deletions

View File

@ -144,7 +144,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
int ret = image_open(&ublast2_firmware_image, low->firmware_path, "ihex");
if (ret != ERROR_OK) {
LOG_ERROR("Could not load firmware image");
return ret;
goto error_release_usb;
}
/** A host loader program must write 0x01 to the CPUCS register
@ -172,7 +172,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
&ublast2_firmware_image, i);
if (ret != ERROR_OK) {
LOG_ERROR("Error while downloading the firmware");
return ret;
goto error_close_firmware;
}
}
@ -187,8 +187,10 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
1,
100);
error_close_firmware:
image_close(&ublast2_firmware_image);
error_release_usb:
/*
* Release claimed interface. Most probably it is already disconnected
* and re-enumerated as new devices after firmware upload, so we do
@ -196,7 +198,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev,
*/
libusb_release_interface(libusb_dev, 0);
return ERROR_OK;
return ret;
}
static int ublast2_libusb_init(struct ublast_lowlevel *low)