This is an automated email from Gerrit.

Spencer Oliver ([email protected]) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/979

-- gerrit

commit 11ae661f4555884c4efb7c4490a70353c7faf00c
Author: Spencer Oliver <[email protected]>
Date:   Wed Nov 14 16:43:25 2012 +0000

    stlink: add generic open error routine
    
    Change-Id: I1cd18896ab2a37255471a2d160befed8dd8fb544
    Signed-off-by: Spencer Oliver <[email protected]>

diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index ab7e78f..b92fb1c 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -1143,6 +1143,21 @@ static int stlink_usb_write_mem32(void *handle, uint32_t 
addr, uint16_t len,
 }
 
 /** */
+static int stlink_usb_close(void *fd)
+{
+       struct stlink_usb_handle_s *h;
+
+       h = (struct stlink_usb_handle_s *)fd;
+
+       if (h->fd)
+               jtag_libusb_close(h->fd);
+
+       free(fd);
+
+       return ERROR_OK;
+}
+
+/** */
 static int stlink_usb_open(struct stlink_interface_param_s *param, void **fd)
 {
        int err;
@@ -1151,7 +1166,7 @@ static int stlink_usb_open(struct 
stlink_interface_param_s *param, void **fd)
 
        LOG_DEBUG("stlink_usb_open");
 
-       h = malloc(sizeof(struct stlink_usb_handle_s));
+       h = calloc(1, sizeof(struct stlink_usb_handle_s));
 
        if (h == 0) {
                LOG_DEBUG("malloc failed");
@@ -1168,14 +1183,14 @@ static int stlink_usb_open(struct 
stlink_interface_param_s *param, void **fd)
 
        if (jtag_libusb_open(vids, pids, &h->fd) != ERROR_OK) {
                LOG_ERROR("open failed");
-               return ERROR_FAIL;
+               goto error_open;
        }
 
        jtag_libusb_set_configuration(h->fd, 0);
 
        if (jtag_libusb_claim_interface(h->fd, 0) != ERROR_OK) {
                LOG_DEBUG("claim interface failed");
-               return ERROR_FAIL;
+               goto error_open;
        }
 
        /* wrap version for first read */
@@ -1193,9 +1208,7 @@ static int stlink_usb_open(struct 
stlink_interface_param_s *param, void **fd)
 
        if (err != ERROR_OK) {
                LOG_ERROR("read version failed");
-               jtag_libusb_close(h->fd);
-               free(h);
-               return err;
+               goto error_open;
        }
 
        /* compare usb vid/pid */
@@ -1224,9 +1237,7 @@ static int stlink_usb_open(struct 
stlink_interface_param_s *param, void **fd)
 
        if (err != ERROR_OK) {
                LOG_ERROR("mode (transport) not supported by device");
-               jtag_libusb_close(h->fd);
-               free(h);
-               return err;
+               goto error_open;
        }
 
        api = h->version.jtag_api_max;
@@ -1246,20 +1257,17 @@ static int stlink_usb_open(struct 
stlink_interface_param_s *param, void **fd)
 
        if (err != ERROR_OK) {
                LOG_ERROR("init mode failed");
-               jtag_libusb_close(h->fd);
-               free(h);
-               return err;
+               goto error_open;
        }
 
        *fd = h;
 
        return ERROR_OK;
-}
 
-/** */
-static int stlink_usb_close(void *fd)
-{
-       return ERROR_OK;
+error_open:
+       stlink_usb_close(h);
+
+       return ERROR_FAIL;
 }
 
 /** */

-- 

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to