summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorAnton Arapov <anton@redhat.com>2010-09-29 10:37:46 +0000
committerAnton Arapov <anton@redhat.com>2010-09-29 10:37:46 +0000
commitcbfb9192bdfdd7534d08a5b36ca008280f40f7dd (patch)
tree6a13869dbc0d1e40b7a50dd15fe4c57a9fa165bc /util.c
parentf6206b6a1f401760493b387a0824b0f6880ca740 (diff)
downloaddmidecode-git-cbfb9192bdfdd7534d08a5b36ca008280f40f7dd.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>
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 8 insertions, 10 deletions
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);