Detailed description
- This is a bugfix to a recently introduced feature (#1757).
- The existing problem is ASan reporting double-free after scanning STM32MP157 SoC.
- The PR solves it by refactoring the (outdated, directly rebased) code to manage reference-counted AP properly and use priv_storage_s.
Tested with BMDA + STLINK/V3MINIE against STM32MP157 in Production and Engi Boot.
There are up to three targets, each allocates an extra AP (some of them will be duplicate), so let's move this from _probe() to _attach(). Then clean up in _detach() but keep in mind that target_list_free() will attempt to free() the priv storage, so it has to become NULL before that. It cannot be automatically freed that way because otherwise DP refcnt results in a small memory leak, reported by ASan (LSan). Finally, cm4 dbgmcu-related code also uses the priv storage, so simply add a pointer field to the struct and cast everywhere to access that.
Your checklist for this pull request
Closing issues
## Detailed description
* This is a bugfix to a recently introduced feature (#1757).
* The existing problem is ASan reporting double-free after scanning STM32MP157 SoC.
* The PR solves it by refactoring the (outdated, directly rebased) code to manage reference-counted AP properly and use priv_storage_s.
Tested with BMDA + STLINK/V3MINIE against STM32MP157 in Production and Engi Boot.
There are up to three targets, each allocates an extra AP (some of them will be duplicate), so let's move this from _probe() to _attach(). Then clean up in _detach() but keep in mind that target_list_free() will attempt to free() the priv storage, so it has to become NULL before that. It cannot be automatically freed that way because otherwise DP refcnt results in a small memory leak, reported by ASan (LSan). Finally, cm4 dbgmcu-related code also uses the priv storage, so simply add a pointer field to the struct and cast everywhere to access that.
## Your checklist for this pull request
* [x] I've read the [Code of Conduct](https://codeberg.org/blackmagic-debug/blackmagic/src/CODE_OF_CONDUCT.md)
* [x] I've read the [guidelines for contributing](https://codeberg.org/blackmagic-debug/blackmagic/src/CONTRIBUTING.md) to this repository
* [x] It builds for hardware native (see [Building the firmware](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-the-firmware))
* [x] It builds as BMDA (see [Building the BMDA](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app))
* [x] I've tested it to the best of my ability
* [x] My commit messages provide a useful short description of what the commits do
## Closing issues