aboutsummaryrefslogtreecommitdiff
path: root/src/flash/nor/msp432.c
diff options
context:
space:
mode:
authorJan Matyas <matyas@codasip.com>2021-04-23 10:47:17 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2021-06-13 19:58:28 +0100
commit64c2e03b23d9cadc1b919d38e902a079d015ddc6 (patch)
tree789350b475b723de7ff22c52cc1b1fefa2f96c2a /src/flash/nor/msp432.c
parentf2958fc04bd879393fa743860478834e234f05d0 (diff)
downloadriscv-openocd-64c2e03b23d9cadc1b919d38e902a079d015ddc6.zip
riscv-openocd-64c2e03b23d9cadc1b919d38e902a079d015ddc6.tar.gz
riscv-openocd-64c2e03b23d9cadc1b919d38e902a079d015ddc6.tar.bz2
flash/nor: improved API of flash_driver.info & fixed buffer overruns
1) The API of "info" callback in "struct flash_driver" has been improved. Fixed buffers for strings 2) Removed the calls to snprintf() from the flash_driver.info implementations. Many of them were used in an unsafe manner (buffer overruns were possible). Change-Id: I42ab8a8018d01f9af43c5ba49f650c3cb5d31dcb Signed-off-by: Jan Matyas <matyas@codasip.com> Reviewed-on: http://openocd.zylin.com/6182 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/flash/nor/msp432.c')
-rw-r--r--src/flash/nor/msp432.c28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/flash/nor/msp432.c b/src/flash/nor/msp432.c
index b6933e1..22f7c77 100644
--- a/src/flash/nor/msp432.c
+++ b/src/flash/nor/msp432.c
@@ -975,60 +975,50 @@ static int msp432_auto_probe(struct flash_bank *bank)
return retval;
}
-static int msp432_info(struct flash_bank *bank, char *buf, int buf_size)
+static int msp432_info(struct flash_bank *bank, struct command_invocation *cmd)
{
struct msp432_bank *msp432_bank = bank->driver_priv;
- int printed = 0;
switch (msp432_bank->device_type) {
case MSP432P401X_DEPR:
if (0xFFFF == msp432_bank->device_id) {
/* Very early pre-production silicon currently deprecated */
- printed = snprintf(buf, buf_size,
- "MSP432P401x pre-production device (deprecated silicon)\n"
+ command_print_sameline(cmd, "MSP432P401x pre-production device (deprecated silicon)\n"
SUPPORT_MESSAGE);
} else {
/* Revision A or B silicon, also deprecated */
- printed = snprintf(buf, buf_size,
- "MSP432P401x Device Rev %c (deprecated silicon)\n"
+ command_print_sameline(cmd, "MSP432P401x Device Rev %c (deprecated silicon)\n"
SUPPORT_MESSAGE, (char)msp432_bank->hardware_rev);
}
break;
case MSP432P401X:
- printed = snprintf(buf, buf_size,
- "MSP432P401x Device Rev %c\n",
+ command_print_sameline(cmd, "MSP432P401x Device Rev %c\n",
(char)msp432_bank->hardware_rev);
break;
case MSP432P411X:
- printed = snprintf(buf, buf_size,
- "MSP432P411x Device Rev %c\n",
+ command_print_sameline(cmd, "MSP432P411x Device Rev %c\n",
(char)msp432_bank->hardware_rev);
break;
case MSP432E401Y:
- printed = snprintf(buf, buf_size, "MSP432E401Y Device\n");
+ command_print_sameline(cmd, "MSP432E401Y Device\n");
break;
case MSP432E411Y:
- printed = snprintf(buf, buf_size, "MSP432E411Y Device\n");
+ command_print_sameline(cmd, "MSP432E411Y Device\n");
break;
case MSP432E4X_GUESS:
- printed = snprintf(buf, buf_size,
+ command_print_sameline(cmd,
"Unrecognized MSP432E4 DID0 and DID1 IDs (%08" PRIX32 ", %08" PRIX32 ")",
msp432_bank->device_id, msp432_bank->hardware_rev);
break;
case MSP432P401X_GUESS:
case MSP432P411X_GUESS:
default:
- printed = snprintf(buf, buf_size,
+ command_print_sameline(cmd,
"Unrecognized MSP432P4 Device ID and Hardware Rev (%04" PRIX32 ", %02" PRIX32 ")",
msp432_bank->device_id, msp432_bank->hardware_rev);
break;
}
- buf_size -= printed;
-
- if (0 > buf_size)
- return ERROR_BUF_TOO_SMALL;
-
return ERROR_OK;
}