target: Separate function to free memory map.

This commit is contained in:
Gareth McMullin 2018-04-10 10:41:53 +12:00
parent 1fd2a24c2d
commit 00decb3718
2 changed files with 22 additions and 14 deletions

View File

@ -54,6 +54,26 @@ bool target_foreach(void (*cb)(int, target *t, void *context), void *context)
return target_list != NULL;
}
void target_mem_map_free(target *t)
{
if (t->dyn_mem_map) {
free(t->dyn_mem_map);
t->dyn_mem_map = NULL;
}
while (t->ram) {
void * next = t->ram->next;
free(t->ram);
t->ram = next;
}
while (t->flash) {
void * next = t->flash->next;
if (t->flash->buf)
free(t->flash->buf);
free(t->flash);
t->flash = next;
}
}
void target_list_free(void)
{
struct target_command_s *tc;
@ -69,20 +89,7 @@ void target_list_free(void)
free(target_list->commands);
target_list->commands = tc;
}
if (target_list->dyn_mem_map)
free(target_list->dyn_mem_map);
while (target_list->ram) {
void * next = target_list->ram->next;
free(target_list->ram);
target_list->ram = next;
}
while (target_list->flash) {
void * next = target_list->flash->next;
if (target_list->flash->buf)
free(target_list->flash->buf);
free(target_list->flash);
target_list->flash = next;
}
target_mem_map_free(target_list);
while (target_list->bw_list) {
void * next = target_list->bw_list->next;
free(target_list->bw_list);

View File

@ -124,6 +124,7 @@ struct target_s {
void (*priv_free)(void *);
};
void target_mem_map_free(target *t);
void target_add_commands(target *t, const struct command_s *cmds, const char *name);
void target_add_ram(target *t, target_addr start, uint32_t len);
void target_add_flash(target *t, struct target_flash *f);