diff options
author | Patrick Georgi <pgeorgi@chromium.org> | 2016-07-29 18:28:42 +0200 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2016-07-31 19:23:29 +0200 |
commit | 1fcebe7fd952d8ea50d421bbc0bd02f23cbf760b (patch) | |
tree | ba683a543c1fe5a159b4814d241f2d23eb3d6360 /util | |
parent | c09160436343ff7f7ce70015f4cca5a03b315f18 (diff) |
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>
Diffstat (limited to 'util')
-rw-r--r-- | util/intelvbttool/intelvbttool.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/util/intelvbttool/intelvbttool.c b/util/intelvbttool/intelvbttool.c index 31fc24a2e0..f0216dd207 100644 --- a/util/intelvbttool/intelvbttool.c +++ b/util/intelvbttool/intelvbttool.c @@ -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; |