mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 07:31:15 +00:00
image: Fix potentially uninitialized data variable
In case fitImage support is disabled, and image_locate_script() is passed a fitImage, then the 'data' variable is used uninitialized. Drop into the default: branch of the switch-case statement and do not return the uninitialized data, and do not modify the return pointer either, just print an error message. Reported by clang build: " $ make HOSTCC=clang CC=clang KCFLAGS=-Werror sandbox64_defconfig && make HOSTCC=clang CC=clang KCFLAGS=-Werror ... boot/image-board.c:1006:7: error: variable 'data' is used uninitialized whenever switch case is taken [-Werror,-Wsometimes-uninitialized] case IMAGE_FORMAT_LEGACY: ^~~~~~~~~~~~~~~~~~~ include/image.h:608:29: note: expanded from macro 'IMAGE_FORMAT_LEGACY' ^~~~ boot/image-board.c:1128:19: note: uninitialized use occurs here *datap = (char *)data; ^~~~ boot/image-board.c:1001:11: note: initialize the variable 'data' to silence this warning u32 *data; ^ = NULL " Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
00491a30b1
commit
771cb4d58b
1 changed files with 11 additions and 4 deletions
|
@ -1004,7 +1004,9 @@ int image_locate_script(void *buf, int size, const char *fit_uname,
|
|||
|
||||
switch (genimg_get_format(buf)) {
|
||||
case IMAGE_FORMAT_LEGACY:
|
||||
if (IS_ENABLED(CONFIG_LEGACY_IMAGE_FORMAT)) {
|
||||
if (!IS_ENABLED(CONFIG_LEGACY_IMAGE_FORMAT)) {
|
||||
goto exit_image_format;
|
||||
} else {
|
||||
hdr = buf;
|
||||
|
||||
if (!image_check_magic(hdr)) {
|
||||
|
@ -1047,7 +1049,9 @@ int image_locate_script(void *buf, int size, const char *fit_uname,
|
|||
}
|
||||
break;
|
||||
case IMAGE_FORMAT_FIT:
|
||||
if (IS_ENABLED(CONFIG_FIT)) {
|
||||
if (!IS_ENABLED(CONFIG_FIT)) {
|
||||
goto exit_image_format;
|
||||
} else {
|
||||
fit_hdr = buf;
|
||||
if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
|
||||
puts("Bad FIT image format\n");
|
||||
|
@ -1121,12 +1125,15 @@ fallback:
|
|||
}
|
||||
break;
|
||||
default:
|
||||
puts("Wrong image format for \"source\" command\n");
|
||||
return -EPERM;
|
||||
goto exit_image_format;
|
||||
}
|
||||
|
||||
*datap = (char *)data;
|
||||
*lenp = len;
|
||||
|
||||
return 0;
|
||||
|
||||
exit_image_format:
|
||||
puts("Wrong image format for \"source\" command\n");
|
||||
return -EPERM;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue