|
From: openocd-gerrit <ope...@us...> - 2026-03-08 10:15:39
|
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 687dd5c5df4583ec0ef4b9dcc9ebd4a6c1968dd8 (commit)
from 0c6fe74351352fad03bd7115a38ef8c7c2ef83f6 (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 687dd5c5df4583ec0ef4b9dcc9ebd4a6c1968dd8
Author: Antonio Borneo <bor...@gm...>
Date: Thu Dec 25 11:31:35 2025 +0100
flash: nor: improve check on memory allocations
Add check for failed allocation.
Add warning for memory allocation fallback and change existing log
from user to more appropriate warning and debug.
Move allocation and check before changing flash information.
Change-Id: I5b2ab6bc12ea15a5d8f634ed00cf0a0bc7e5a517
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9384
Tested-by: jenkins
Reviewed-by: Tomas Vanek <va...@fb...>
Reviewed-by: Marc Schink <de...@za...>
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index 48440662e..2c41d1853 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -336,6 +336,10 @@ static int default_flash_mem_blank_check(struct flash_bank *bank)
}
uint8_t *buffer = malloc(buffer_size);
+ if (!buffer) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t j;
@@ -382,8 +386,10 @@ int default_flash_blank_check(struct flash_bank *bank)
struct target_memory_check_block *block_array;
block_array = malloc(bank->num_sectors * sizeof(struct target_memory_check_block));
- if (!block_array)
+ if (!block_array) {
+ LOG_WARNING("Running slow fallback erase check - limited host memory available");
return default_flash_mem_blank_check(bank);
+ }
for (unsigned int i = 0; i < bank->num_sectors; i++) {
block_array[i].address = bank->base + bank->sectors[i].offset;
@@ -413,9 +419,9 @@ int default_flash_blank_check(struct flash_bank *bank)
retval = ERROR_OK;
} else {
if (retval == ERROR_NOT_IMPLEMENTED)
- LOG_USER("Running slow fallback erase check");
+ LOG_DEBUG("Running slow fallback erase check");
else
- LOG_USER("Running slow fallback erase check - add working memory");
+ LOG_WARNING("Running slow fallback erase check - add working memory");
retval = default_flash_mem_blank_check(bank);
}
@@ -729,11 +735,25 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
unsigned int section;
uint32_t section_offset;
struct flash_bank *c;
- int *padding;
section = 0;
section_offset = 0;
+ /* allocate padding array */
+ int *padding = calloc(image->num_sections, sizeof(*padding));
+
+ /* This fn requires all sections to be in ascending order of addresses,
+ * whereas an image can have sections out of order. */
+ struct imagesection **sections = malloc(sizeof(struct imagesection *) *
+ image->num_sections);
+
+ if (!padding || !sections) {
+ LOG_ERROR("Out of memory");
+ free(padding);
+ free(sections);
+ return ERROR_FAIL;
+ }
+
if (written)
*written = 0;
@@ -744,14 +764,6 @@ int flash_write_unlock_verify(struct target *target, struct image *image,
flash_set_dirty();
}
- /* allocate padding array */
- padding = calloc(image->num_sections, sizeof(*padding));
-
- /* This fn requires all sections to be in ascending order of addresses,
- * whereas an image can have sections out of order. */
- struct imagesection **sections = malloc(sizeof(struct imagesection *) *
- image->num_sections);
-
for (unsigned int i = 0; i < image->num_sections; i++)
sections[i] = &image->sections[i];
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/core.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|