From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeroen Hofstee Date: Thu, 13 Nov 2014 22:42:31 +0100 Subject: [U-Boot] [PATCH] tools/kwbimage.c: fix parser error handling In-Reply-To: <544E3548.4040405@myspectrum.nl> References: <1414185952-2227-1-git-send-email-andreas.devel@googlemail.com> <544E3548.4040405@myspectrum.nl> Message-ID: <546525C7.5000500@myspectrum.nl> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hello Andreas, On 27-10-14 13:06, Jeroen Hofstee wrote: > Hello Andreas, > > On 24-10-14 23:25, andreas.devel at googlemail.com wrote: >> From: Andreas Bie?mann >> >> The two error checks for image_boot_mode_id and >> image_nand_ecc_mode_id where >> wrong and would never fail, fix that! >> >> This was detected by Apple's clang compiler: >> ---8<--- >> HOSTCC tools/kwbimage.o >> tools/kwbimage.c:553:20: warning: comparison of unsigned expression < >> 0 is always false [-Wtautological-compare] >> if (el->bootfrom < 0) { >> ~~~~~~~~~~~~ ^ ~ >> tools/kwbimage.c:571:23: warning: comparison of unsigned expression < >> 0 is always false [-Wtautological-compare] >> if (el->nandeccmode < 0) { >> ~~~~~~~~~~~~~~~ ^ ~ >> 2 warnings generated. >> --->8--- >> >> Signed-off-by: Andreas Bie?mann >> --- >> >> tools/kwbimage.c | 14 ++++++++------ >> 1 file changed, 8 insertions(+), 6 deletions(-) >> >> diff --git a/tools/kwbimage.c b/tools/kwbimage.c >> index 42870ed..8fd70ef 100644 >> --- a/tools/kwbimage.c >> +++ b/tools/kwbimage.c >> @@ -548,13 +548,14 @@ static int >> image_create_config_parse_oneline(char *line, >> el->version = atoi(value); >> } else if (!strcmp(keyword, "BOOT_FROM")) { >> char *value = strtok_r(NULL, deliminiters, &saveptr); >> - el->type = IMAGE_CFG_BOOT_FROM; >> - el->bootfrom = image_boot_mode_id(value); >> - if (el->bootfrom < 0) { >> + int ret = image_boot_mode_id(value); >> + if (ret < 0) { >> fprintf(stderr, >> "Invalid boot media '%s'\n", value); >> return -1; >> } >> + el->type = IMAGE_CFG_BOOT_FROM; >> + el->bootfrom = ret; >> } else if (!strcmp(keyword, "NAND_BLKSZ")) { >> char *value = strtok_r(NULL, deliminiters, &saveptr); >> el->type = IMAGE_CFG_NAND_BLKSZ; >> @@ -566,13 +567,14 @@ static int >> image_create_config_parse_oneline(char *line, >> strtoul(value, NULL, 16); >> } else if (!strcmp(keyword, "NAND_ECC_MODE")) { >> char *value = strtok_r(NULL, deliminiters, &saveptr); >> - el->type = IMAGE_CFG_NAND_ECC_MODE; >> - el->nandeccmode = image_nand_ecc_mode_id(value); >> - if (el->nandeccmode < 0) { >> + int ret = image_nand_ecc_mode_id(value); > > Thanks for fixing this. Could you move the int ret declaration before > actual code though? Ah, I see now, you were not adding the declaration in the middle of the code. There is just a newline missing after the declaration, which make the patch look like it does. This was already the case in the original code, so Acked-By: Jeroen Hofstee Regards, Jeroen