drivers: USB Blaster II: close file and release USB device if firmware handling failed 15/6115/2
authorOleksij Rempel <o.rempel@pengutronix.de>
Thu, 18 Mar 2021 17:47:35 +0000 (18:47 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Fri, 19 Mar 2021 22:01:54 +0000 (22:01 +0000)
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>
src/jtag/drivers/usb_blaster/ublast2_access_libusb.c

index 82dc95071f625fa7a1d05933eacb1f45cd2121eb..4dec89b113ba92d58a82cf0c8cc87553ded061f0 100644 (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)

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)