diff options
author | aarapov <aarapov> | 2010-09-29 10:37:46 +0000 |
---|---|---|
committer | aarapov <aarapov> | 2010-09-29 10:37:46 +0000 |
commit | 84b661313b5ab8313103e2db926e91cc54dec225 (patch) | |
tree | 6a13869dbc0d1e40b7a50dd15fe4c57a9fa165bc | |
parent | 572b51cd2978338f724681179bd4059b1e7ee844 (diff) | |
download | dmidecode-84b661313b5ab8313103e2db926e91cc54dec225.tar.gz |
* util.c: makes dmidecode fall back to regular reads if the mmap
fails. Patch from Olof Johansson.
original author's comment:
Date: Tue, 28 Sep 2010 15:48:44 -0500
From: Olof Johansson <olof@lixom.net>
To: Jean Delvare <khali@linux-fr.org>
Cc: anton@redhat.com
Subject: [PATCH] dmidecode: fall back to regular reads
Message-ID: <20100928204844.GA19541@lixom.net>
Hi,
Following patch makes dmidecode fall back to regular reads if the mmap fails.
I've got a patch I will send out that exports the DMI blob under debugfs, and
said files can't be mmapped.
Signed-off-by: Olof Johansson <olof@lixom.net>
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | CHANGELOG | 5 | ||||
-rw-r--r-- | util.c | 18 |
3 files changed, 14 insertions, 10 deletions
@@ -73,3 +73,4 @@ Andreas Gruenbacher Lin Li Thomas Hiller Paul Flo Williams +Olof Johansson @@ -1,3 +1,8 @@ +2010-09-29 Anton Arapov <anton@redhat.com> + + * util.c: makes dmidecode fall back to regular reads if the mmap + fails. Patch from Olof Johansson. + 2010-09-21 Jean Delvare <khali@linux-fr.org> * dmidecode.c: Fix Xeon 7xxx entries in CPU name lookup table @@ -47,7 +47,6 @@ #include "types.h" #include "util.h" -#ifndef USE_MMAP static int myread(int fd, u8 *buf, size_t count, const char *prefix) { ssize_t r = 1; @@ -78,7 +77,6 @@ static int myread(int fd, u8 *buf, size_t count, const char *prefix) return 0; } -#endif int checksum(const u8 *buf, size_t len) { @@ -128,12 +126,7 @@ void *mem_chunk(size_t base, size_t len, const char *devmem) */ mmp = mmap(0, mmoffset + len, PROT_READ, MAP_SHARED, fd, base - mmoffset); if (mmp == MAP_FAILED) - { - fprintf(stderr, "%s: ", devmem); - perror("mmap"); - free(p); - return NULL; - } + goto try_read; memcpy(p, (u8 *)mmp + mmoffset, len); @@ -142,7 +135,12 @@ void *mem_chunk(size_t base, size_t len, const char *devmem) fprintf(stderr, "%s: ", devmem); perror("munmap"); } -#else /* USE_MMAP */ + + goto out; + +#endif /* USE_MMAP */ + +try_read: if (lseek(fd, base, SEEK_SET) == -1) { fprintf(stderr, "%s: ", devmem); @@ -156,8 +154,8 @@ void *mem_chunk(size_t base, size_t len, const char *devmem) free(p); return NULL; } -#endif /* USE_MMAP */ +out: if (close(fd) == -1) perror(devmem); |