mirror of
https://xff.cz/git/u-boot/
synced 2025-10-01 15:31:27 +02:00
tools: imx8image: check lseek return value
Check lseek return value. Fix Coverity CID: 184236 184235 184232 Reported-by: Coverity Signed-off-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Fabio Estevam <festevam@gmail.com>
This commit is contained in:
@@ -301,6 +301,7 @@ static void copy_file_aligned(int ifd, const char *datafile, int offset,
|
|||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
uint8_t zeros[0x4000];
|
uint8_t zeros[0x4000];
|
||||||
int size;
|
int size;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (align > 0x4000) {
|
if (align > 0x4000) {
|
||||||
fprintf(stderr, "Wrong alignment requested %d\n", align);
|
fprintf(stderr, "Wrong alignment requested %d\n", align);
|
||||||
@@ -333,7 +334,13 @@ static void copy_file_aligned(int ifd, const char *datafile, int offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
size = sbuf.st_size;
|
size = sbuf.st_size;
|
||||||
lseek(ifd, offset, SEEK_SET);
|
ret = lseek(ifd, offset, SEEK_SET);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "%s: lseek error %s\n",
|
||||||
|
__func__, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (write(ifd, ptr, size) != size) {
|
if (write(ifd, ptr, size) != size) {
|
||||||
fprintf(stderr, "Write error %s\n", strerror(errno));
|
fprintf(stderr, "Write error %s\n", strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -359,7 +366,7 @@ static void copy_file (int ifd, const char *datafile, int pad, int offset)
|
|||||||
int tail;
|
int tail;
|
||||||
int zero = 0;
|
int zero = 0;
|
||||||
uint8_t zeros[4096];
|
uint8_t zeros[4096];
|
||||||
int size;
|
int size, ret;
|
||||||
|
|
||||||
memset(zeros, 0, sizeof(zeros));
|
memset(zeros, 0, sizeof(zeros));
|
||||||
|
|
||||||
@@ -387,7 +394,13 @@ static void copy_file (int ifd, const char *datafile, int pad, int offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size = sbuf.st_size;
|
size = sbuf.st_size;
|
||||||
lseek(ifd, offset, SEEK_SET);
|
ret = lseek(ifd, offset, SEEK_SET);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "%s: lseek error %s\n",
|
||||||
|
__func__, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (write(ifd, ptr, size) != size) {
|
if (write(ifd, ptr, size) != size) {
|
||||||
fprintf(stderr, "Write error %s\n",
|
fprintf(stderr, "Write error %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@@ -762,6 +775,7 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
|
|||||||
char *tmp_filename = NULL;
|
char *tmp_filename = NULL;
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
uint32_t file_padding = 0;
|
uint32_t file_padding = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
int container = -1;
|
int container = -1;
|
||||||
int cont_img_count = 0; /* indexes to arrange the container */
|
int cont_img_count = 0; /* indexes to arrange the container */
|
||||||
@@ -883,7 +897,12 @@ static int build_container(soc_type_t soc, uint32_t sector_size,
|
|||||||
} while (img_sp->option != NO_IMG);
|
} while (img_sp->option != NO_IMG);
|
||||||
|
|
||||||
/* Add padding or skip appended container */
|
/* Add padding or skip appended container */
|
||||||
lseek(ofd, file_padding, SEEK_SET);
|
ret = lseek(ofd, file_padding, SEEK_SET);
|
||||||
|
if (ret < 0) {
|
||||||
|
fprintf(stderr, "%s: lseek error %s\n",
|
||||||
|
__func__, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Note: Image offset are not contained in the image */
|
/* Note: Image offset are not contained in the image */
|
||||||
tmp = flatten_container_header(&imx_header, container + 1, &size,
|
tmp = flatten_container_header(&imx_header, container + 1, &size,
|
||||||
|
Reference in New Issue
Block a user