summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraarapov <aarapov>2010-09-29 10:37:46 +0000
committeraarapov <aarapov>2010-09-29 10:37:46 +0000
commit84b661313b5ab8313103e2db926e91cc54dec225 (patch)
tree6a13869dbc0d1e40b7a50dd15fe4c57a9fa165bc
parent572b51cd2978338f724681179bd4059b1e7ee844 (diff)
downloaddmidecode-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--AUTHORS1
-rw-r--r--CHANGELOG5
-rw-r--r--util.c18
3 files changed, 14 insertions, 10 deletions
diff --git a/AUTHORS b/AUTHORS
index 7b1eedd..9d8fe1e 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -73,3 +73,4 @@ Andreas Gruenbacher
Lin Li
Thomas Hiller
Paul Flo Williams
+Olof Johansson
diff --git a/CHANGELOG b/CHANGELOG
index a1f2ccc..9562c39 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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
diff --git a/util.c b/util.c
index 15d24a7..d292bf8 100644
--- a/util.c
+++ b/util.c
@@ -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);