arm_adi_v5: fix SIGSEGV due to failing re-examine
commitc6fe10de75763623dfdaaf2fe3fff7e78a4ca146
authorAntonio Borneo <borneo.antonio@gmail.com>
Sat, 10 Dec 2022 17:19:54 +0000 (10 18:19 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 17 Dec 2022 09:30:45 +0000 (17 09:30 +0000)
tree7971d0555080c0930fc96c8cd58584a1ce045f68
parent2278878a05d8dfbbed3e59f0cfbeeb598af3129c
arm_adi_v5: fix SIGSEGV due to failing re-examine

Commit 35a503b08d14 ("arm_adi_v5: add ap refcount and add get/put
around ap use") modifies the examine functions of mem_ap, cortex_m,
cortex_a and aarch64 by calling dap_put_ap() and then looking again
for the mem-ap and calling dap_get_ap().
This causes an issue if the system is irresponsive and the examine
fails and left the AP pointer to NULL. If the system was already
examined the NULL pointer will cause a SIGSEGV.

Commit b6dad912b85d ("target/cortex_m: prevent segmentation fault
in cortex_m_poll()") proposes a fix for one specific case and only
on cortex_m.

Modify all the examine functions by skipping look-up for the AP if
it was already set in a previous examine; the target's AP is not
supposed to change during runtime.

Remove the partial fix for cortex_m as it is not needed anymore.

Change-Id: I806ec3b1b02fcc76e141c8dd3a65044febbf0a8c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 35a503b08d14 ("arm_adi_v5: add ap refcount and add get/put around ap use")
Reviewed-on: https://review.openocd.org/c/openocd/+/7392
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/target/aarch64.c
src/target/cortex_a.c
src/target/cortex_m.c
src/target/mem_ap.c