From 925056da0213e41f4845a262cfdc311a530296b1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 14 Jun 2010 23:05:23 +0000 Subject: [PATCH] idcode: clean up code a bit and dont leak resources on error git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1787 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 4 ++++ urjtag/src/tap/idcode.c | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 6aefd685..6449de45 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -10,6 +10,10 @@ * src/tap/parport/ppi.c (ppi_connect): Fix return type to match expected, and tweak style to match ppdev.c better. + * src/tap/idcode.c (urj_tap_idcode): Fix typo in comment (bits, not bytes), + fix local types so we don't mismatch signs, and avoid leaking register + allocations with the error handling. + 2010-05-19 Arnim Laeuger * src/flash/amd.c, doc/UrJTAG.txt: [ 2996919 ] Support for MX29LV320C diff --git a/urjtag/src/tap/idcode.c b/urjtag/src/tap/idcode.c index ba942667..917c2fdd 100644 --- a/urjtag/src/tap/idcode.c +++ b/urjtag/src/tap/idcode.c @@ -34,28 +34,32 @@ int urj_tap_idcode (urj_chain_t *chain, unsigned int bytes) { - int i; - int hit = 0; + int ret; + unsigned int i, hit, max_bytes; urj_tap_register_t *rz; urj_tap_register_t *rout; urj_tap_register_t *rnull; + ret = URJ_STATUS_FAIL; + max_bytes = bytes ? bytes : 1000; + hit = 0; + urj_tap_chain_set_trst (chain, 0); urj_tap_chain_set_trst (chain, 1); urj_tap_reset (chain); urj_tap_capture_dr (chain); - /* read in chunks of 8 bytes */ + /* read in chunks of 8 bits */ rz = urj_tap_register_fill (urj_tap_register_alloc (8), 0); rnull = urj_tap_register_fill (urj_tap_register_alloc (8), 0); rout = urj_tap_register_alloc (8); if (!rz || !rout || !rnull) - return URJ_STATUS_FAIL; + goto done; urj_log (URJ_LOG_LEVEL_NORMAL, _("Read")); - for (i = 0; i < ((bytes) ? bytes : 1000); i++) + for (i = 0; i < max_bytes; ++i) { uint8_t val; urj_tap_shift_register (chain, rz, rout, 0); @@ -74,10 +78,13 @@ urj_tap_idcode (urj_chain_t *chain, unsigned int bytes) break; } } + urj_log (URJ_LOG_LEVEL_NORMAL, _("\n")); + ret = URJ_STATUS_OK; + + done: urj_tap_register_free (rz); urj_tap_register_free (rnull); urj_tap_register_free (rout); - urj_log (URJ_LOG_LEVEL_NORMAL, _("\n")); - return URJ_STATUS_OK; + return ret; }