intelvbttool: cope with errors in open()

Change-Id: I9fee87b7331ee05d4e984cb024f124abb2c97a69
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Found-by: Coverity Scan #1347357
Reviewed-on: https://review.coreboot.org/15962
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
This commit is contained in:
Patrick Georgi 2016-07-29 18:28:42 +02:00 committed by Martin Roth
parent c091604363
commit 1fcebe7fd9
1 changed files with 9 additions and 2 deletions

View File

@ -515,13 +515,20 @@ int main(int argc, char **argv)
{
const void *ptr;
int fd;
off_t offset;
if (argc == 2) {
fd = open(argv[1], O_RDONLY);
ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);
offset = 0;
} else {
fd = open("/dev/mem", O_RDONLY);
ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0xc0000);
offset = 0xc0000;
}
if (fd < 0) {
fprintf(stderr, "open failed: %s\n", strerror(errno));
return 1;
}
ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, offset);
if (ptr == MAP_FAILED) {
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
return 1;