From: OpenOCD-Gerrit <ope...@us...> - 2020-07-08 21:08:20
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via f29d157882a756e562d224dd128eea1bbe3e3813 (commit) via 6a81bad3b973e54ce68496d22750d643741afb32 (commit) from 327d18220ffb005884a742992657b6b5a4be2232 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f29d157882a756e562d224dd128eea1bbe3e3813 Author: Antonio Borneo <bor...@gm...> Date: Sun Jun 14 23:18:21 2020 +0200 target/arm926ejs: fix memory leaks The memory leaks detected and fixed are: - arm register cache; - EmbeddedICE register cache; - arm_jtag_reset_callback internal data; - struct arm926ejs_common. Issue identified with valgrind. Tested on SPEAr320 based on arm926ejs. Change-Id: If2bed02c516051ce4d0eb29b204a3f3337fe5d6a Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5698 Tested-by: jenkins diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 6a7bf9da5..28fefc5aa 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2682,6 +2682,15 @@ int arm7_9_examine(struct target *target) return retval; } +void arm7_9_deinit(struct target *target) +{ + struct arm7_9_common *arm7_9 = target_to_arm7_9(target); + + if (target_was_examined(target)) + embeddedice_free_reg_cache(arm7_9->eice_cache); + + arm_jtag_close_connection(&arm7_9->jtag_info); +} int arm7_9_check_reset(struct target *target) { diff --git a/src/target/arm7_9_common.h b/src/target/arm7_9_common.h index 811f9c593..4961212bb 100644 --- a/src/target/arm7_9_common.h +++ b/src/target/arm7_9_common.h @@ -186,6 +186,7 @@ int arm7_9_execute_sys_speed(struct target *target); int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9); int arm7_9_examine(struct target *target); +void arm7_9_deinit(struct target *target); int arm7_9_check_reset(struct target *target); int arm7_9_endianness_callback(jtag_callback_data_t pu8_in, diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index ac30485b8..95a4f7ca0 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -723,6 +723,16 @@ static int arm926ejs_target_create(struct target *target, Jim_Interp *interp) return arm926ejs_init_arch_info(target, arm926ejs, target->tap); } +void arm926ejs_deinit_target(struct target *target) +{ + struct arm *arm = target_to_arm(target); + struct arm926ejs_common *arm926ejs = target_to_arm926(target); + + arm7_9_deinit(target); + arm_free_reg_cache(arm); + free(arm926ejs); +} + COMMAND_HANDLER(arm926ejs_handle_cache_info_command) { int retval; @@ -823,6 +833,7 @@ struct target_type arm926ejs_target = { .commands = arm926ejs_command_handlers, .target_create = arm926ejs_target_create, .init_target = arm9tdmi_init_target, + .deinit_target = arm926ejs_deinit_target, .examine = arm7_9_examine, .check_reset = arm7_9_check_reset, .virt2phys = arm926ejs_virt2phys, diff --git a/src/target/arm_jtag.c b/src/target/arm_jtag.c index 49aca3487..f9605acb1 100644 --- a/src/target/arm_jtag.c +++ b/src/target/arm_jtag.c @@ -92,3 +92,8 @@ int arm_jtag_setup_connection(struct arm_jtag *jtag_info) return jtag_register_event_callback(arm_jtag_reset_callback, jtag_info); } + +int arm_jtag_close_connection(struct arm_jtag *jtag_info) +{ + return jtag_unregister_event_callback(arm_jtag_reset_callback, jtag_info); +} diff --git a/src/target/arm_jtag.h b/src/target/arm_jtag.h index bb92abb84..bf5b83748 100644 --- a/src/target/arm_jtag.h +++ b/src/target/arm_jtag.h @@ -61,6 +61,7 @@ static inline int arm_jtag_scann(struct arm_jtag *jtag_info, uint32_t new_scan_c } int arm_jtag_setup_connection(struct arm_jtag *jtag_info); +int arm_jtag_close_connection(struct arm_jtag *jtag_info); /* use this as a static so we can inline it in -O3 and refer to it via a pointer */ static inline void arm7flip32(jtag_callback_data_t arg) diff --git a/src/target/embeddedice.c b/src/target/embeddedice.c index 61ee8bbd9..7c53c45c5 100644 --- a/src/target/embeddedice.c +++ b/src/target/embeddedice.c @@ -303,6 +303,22 @@ struct reg_cache *embeddedice_build_reg_cache(struct target *target, return reg_cache; } +/** + * Free all memory allocated for EmbeddedICE register cache + */ +void embeddedice_free_reg_cache(struct reg_cache *reg_cache) +{ + if (!reg_cache) + return; + + for (unsigned int i = 0; i < reg_cache->num_regs; i++) + free(reg_cache->reg_list[i].value); + + free(reg_cache->reg_list[0].arch_info); + free(reg_cache->reg_list); + free(reg_cache); +} + /** * Initialize EmbeddedICE module, if needed. */ diff --git a/src/target/embeddedice.h b/src/target/embeddedice.h index 39902fb3e..4b5c816a6 100644 --- a/src/target/embeddedice.h +++ b/src/target/embeddedice.h @@ -88,6 +88,7 @@ struct embeddedice_reg { struct reg_cache *embeddedice_build_reg_cache(struct target *target, struct arm7_9_common *arm7_9); +void embeddedice_free_reg_cache(struct reg_cache *reg_cache); int embeddedice_setup(struct target *target); commit 6a81bad3b973e54ce68496d22750d643741afb32 Author: Antonio Borneo <bor...@gm...> Date: Wed Jun 10 16:08:41 2020 +0200 configure: split build of hla layouts Current hla driver supports two "layout": stlink and ti-icdi. The configure script allows to independently enable/disable the the two layout. But in reality by selecting only one of them the whole hla driver is built, including both "layouts". This is currently not a big issue because the dependencies of the two layout are the same (libusb), so we are sure that selecting one of them would permit to build both. This is going to change with the merge of a third "layout" for Nuvoton Nu-Link, because it would be based on hidapi. We need, at least, to decouple the build of libusb and hidapi "layouts". A full decouple of each "layout" is also welcome to match the selection done during configure. Introduce a new automake macro for each of the two "layout" and use them to conditionally build the "layout" files. Use the existing autoconf macros to conditionally compile the code that depends by the "layout". Change-Id: Ia20da7a260002a8d2af883425aa401b8920d3f36 Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5719 Tested-by: jenkins diff --git a/configure.ac b/configure.ac index a6bda8856..382a00b6e 100644 --- a/configure.ac +++ b/configure.ac @@ -683,10 +683,13 @@ AS_IF([test "x$build_openjtag" = "xyes"], [ AS_IF([test "x$enable_stlink" != "xno" -o "x$enable_ti_icdi" != "xno"], [ AC_DEFINE([BUILD_HLADAPTER], [1], [1 if you want the High Level JTAG driver.]) + AM_CONDITIONAL([HLADAPTER], [true]) ], [ AC_DEFINE([BUILD_HLADAPTER], [0], [0 if you want the High Level JTAG driver.]) + AM_CONDITIONAL([HLADAPTER], [false]) ]) -AM_CONDITIONAL([HLADAPTER], [test "x$enable_stlink" != "xno" -o "x$enable_ti_icdi" != "xno"]) +AM_CONDITIONAL([HLADAPTER_STLINK], [test "x$enable_stlink" != "xno"]) +AM_CONDITIONAL([HLADAPTER_ICDI], [test "x$enable_ti_icdi" != "xno"]) AS_IF([test "x$enable_jlink" != "xno"], [ AS_IF([test "x$use_internal_libjaylink" = "xyes"], [ diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am index 07824f678..b03f560b3 100644 --- a/src/jtag/drivers/Makefile.am +++ b/src/jtag/drivers/Makefile.am @@ -129,8 +129,10 @@ endif if REMOTE_BITBANG DRIVERFILES += %D%/remote_bitbang.c endif -if HLADAPTER +if HLADAPTER_STLINK DRIVERFILES += %D%/stlink_usb.c +endif +if HLADAPTER_ICDI DRIVERFILES += %D%/ti_icdi_usb.c endif if RSHIM diff --git a/src/jtag/hla/hla_layout.c b/src/jtag/hla/hla_layout.c index c5e35182d..686e6f5b2 100644 --- a/src/jtag/hla/hla_layout.c +++ b/src/jtag/hla/hla_layout.c @@ -57,18 +57,22 @@ static int hl_layout_close(struct hl_interface_s *adapter) } static const struct hl_layout hl_layouts[] = { +#if BUILD_HLADAPTER_STLINK { .name = "stlink", .open = hl_layout_open, .close = hl_layout_close, .api = &stlink_usb_layout_api, }, +#endif +#if BUILD_HLADAPTER_ICDI { .name = "ti-icdi", .open = hl_layout_open, .close = hl_layout_close, .api = &icdi_usb_layout_api, }, +#endif {.name = NULL, /* END OF TABLE */ }, }; diff --git a/src/jtag/interfaces.c b/src/jtag/interfaces.c index 7d3f8a8ca..87ea95822 100644 --- a/src/jtag/interfaces.c +++ b/src/jtag/interfaces.c @@ -138,7 +138,7 @@ extern struct adapter_driver imx_gpio_adapter_driver; #if BUILD_XDS110 == 1 extern struct adapter_driver xds110_adapter_driver; #endif -#if BUILD_HLADAPTER == 1 +#if BUILD_HLADAPTER_STLINK == 1 extern struct adapter_driver stlink_dap_adapter_driver; #endif #if BUILD_RSHIM == 1 @@ -252,7 +252,7 @@ struct adapter_driver *adapter_drivers[] = { #if BUILD_XDS110 == 1 &xds110_adapter_driver, #endif -#if BUILD_HLADAPTER == 1 +#if BUILD_HLADAPTER_STLINK == 1 &stlink_dap_adapter_driver, #endif #if BUILD_RSHIM == 1 ----------------------------------------------------------------------- Summary of changes: configure.ac | 5 ++++- src/jtag/drivers/Makefile.am | 4 +++- src/jtag/hla/hla_layout.c | 4 ++++ src/jtag/interfaces.c | 4 ++-- src/target/arm7_9_common.c | 9 +++++++++ src/target/arm7_9_common.h | 1 + src/target/arm926ejs.c | 11 +++++++++++ src/target/arm_jtag.c | 5 +++++ src/target/arm_jtag.h | 1 + src/target/embeddedice.c | 16 ++++++++++++++++ src/target/embeddedice.h | 1 + 11 files changed, 57 insertions(+), 4 deletions(-) hooks/post-receive -- Main OpenOCD repository |