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:
parent
c091604363
commit
1fcebe7fd9
|
@ -515,13 +515,20 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const void *ptr;
|
const void *ptr;
|
||||||
int fd;
|
int fd;
|
||||||
|
off_t offset;
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
fd = open(argv[1], O_RDONLY);
|
fd = open(argv[1], O_RDONLY);
|
||||||
ptr = mmap(0, 65536, PROT_READ, MAP_SHARED, fd, 0);
|
offset = 0;
|
||||||
} else {
|
} else {
|
||||||
fd = open("/dev/mem", O_RDONLY);
|
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) {
|
if (ptr == MAP_FAILED) {
|
||||||
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
|
fprintf(stderr, "mmap failed: %s\n", strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue