From 29ff10743f8bccd61a48abdb38c891a9a23c4bea Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Fri, 21 Dec 2012 04:52:13 +0100 Subject: [PATCH 1/2] libztex: check returnvalue of libusb_claim_interface() and release the interface in case of early exit --- libztex.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libztex.c b/libztex.c index 54b426bf..91bdc959 100644 --- a/libztex.c +++ b/libztex.c @@ -370,12 +370,17 @@ static int libztex_configureFpgaHS(struct libztex_device *ztex, const char* firm return cnt; } - libusb_claim_interface(ztex->hndl, settings[1]); + err = libusb_claim_interface(ztex->hndl, settings[1]); + if (err != LIBUSB_SUCCESS) { + applog(LOG_ERR, "%s: failed to claim interface for hs transfer", ztex->repr); + return -4; + } for (tries = 3; tries > 0; tries--) { fp = open_bitstream("ztex", firmware); if (!fp) { applog(LOG_ERR, "%s: failed to read bitstream '%s'", ztex->repr, firmware); + libusb_release_interface(ztex->hndl, settings[1]); return -2; } @@ -409,6 +414,7 @@ static int libztex_configureFpgaHS(struct libztex_device *ztex, const char* firm libztex_getFpgaState(ztex, &state); if (!state.fpgaConfigured) { applog(LOG_ERR, "%s: HS FPGA configuration failed: DONE pin does not go high", ztex->repr); + libusb_release_interface(ztex->hndl, settings[1]); return -3; } } From 01d7b261ebb00cea2cebc094604220e036df10f6 Mon Sep 17 00:00:00 2001 From: Denis Ahrens Date: Fri, 14 Dec 2012 15:05:34 +0100 Subject: [PATCH 2/2] libztex: fixed a typo --- libztex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libztex.c b/libztex.c index 91bdc959..71d62003 100644 --- a/libztex.c +++ b/libztex.c @@ -468,7 +468,7 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm cnt = libusb_control_transfer(ztex->hndl, 0x40, 0x32, 0, 0, buf, length, 5000); if (cnt != length) { - applog(LOG_ERR, "%s: Failed send hs fpga data", ztex->repr); + applog(LOG_ERR, "%s: Failed send ls fpga data", ztex->repr); break; } }