From 505268cd93523ea3484e1e4132546eac6fab6821 Mon Sep 17 00:00:00 2001 From: Adrian Bonislawski Date: Tue, 28 Nov 2023 10:34:56 +0100 Subject: [PATCH] rimage: elf: fixed error handling from file operation Fixes error handling Signed-off-by: Adrian Bonislawski (cherry picked from commit fd61ed615122d44c3917ba5daaad4faef63689c4) Signed-off-by: Kai Vehmanen --- tools/rimage/src/elf_file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/rimage/src/elf_file.c b/tools/rimage/src/elf_file.c index efb9cc912b4e..e143b9ef585d 100644 --- a/tools/rimage/src/elf_file.c +++ b/tools/rimage/src/elf_file.c @@ -117,7 +117,7 @@ static int elf_header_read(struct elf_file *elf) /* read in elf header */ count = fread(&elf->header, sizeof(elf->header), 1, elf->file); if (count != 1) { - if (count < 0) + if (!count) return file_error("failed to read elf header", elf->filename); else return elf_error(elf, "Corrupted file.", ENODATA); @@ -199,7 +199,7 @@ static int elf_section_headers_read(struct elf_file *elf) count = fread(&elf->sections[i].data, sizeof(Elf32_Shdr), 1, elf->file); if (count != 1) { - if (count < 0) + if (!count) return file_error("failed to read section header", elf->filename); else return elf_error(elf, "Corrupted file.", ENODATA); @@ -264,7 +264,7 @@ static int elf_program_headers_read(struct elf_file *elf) count = fread(&elf->programs[i], sizeof(Elf32_Phdr), 1, elf->file); if (count != 1) { - if (count < 0) + if (!count) return file_error("failed to read program header", elf->filename); else return elf_error(elf, "Corrupted file.", ENODATA); @@ -467,7 +467,7 @@ int elf_section_read_content(const struct elf_file *elf, const struct elf_sectio count = fread(buffer, header->data.size, 1, elf->file); if (count != 1) { - if (count < 0) + if (!count) return file_error("failed to read section data", elf->filename); else return elf_error(elf, "Corrupted file.", ENODATA);