|
|
3ea658 |
From 9967415630f6e58da27ebd33a32d1f1bb1f6ba78 Mon Sep 17 00:00:00 2001
|
|
|
3ea658 |
From: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
|
|
|
3ea658 |
Date: Thu, 15 Jan 2015 22:39:26 +0200
|
|
|
3ea658 |
Subject: [PATCH 3/4] dmidecode: move memory map function from dmi_decode
|
|
|
3ea658 |
|
|
|
3ea658 |
There is no reason to allocate/copy/free memory for dmi_table inside
|
|
|
3ea658 |
function. It's more convenient to do it outside. In this case we can
|
|
|
3ea658 |
use dmi_decode function with already allocated memory like in case
|
|
|
3ea658 |
with dmifs library. The same is for dmi_table_dump().
|
|
|
3ea658 |
|
|
|
3ea658 |
Signed-off-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
|
|
|
3ea658 |
---
|
|
|
3ea658 |
dmidecode.c | 70 ++++++++++++++++++++++++++++++++++++-------------------------
|
|
|
3ea658 |
1 file changed, 41 insertions(+), 29 deletions(-)
|
|
|
3ea658 |
|
|
|
3ea658 |
diff --git a/dmidecode.c b/dmidecode.c
|
|
|
3ea658 |
index 4e4a82f..2fedddc 100644
|
|
|
3ea658 |
--- a/dmidecode.c
|
|
|
3ea658 |
+++ b/dmidecode.c
|
|
|
3ea658 |
@@ -4340,25 +4340,15 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
|
|
|
3ea658 |
}
|
|
|
3ea658 |
}
|
|
|
3ea658 |
|
|
|
3ea658 |
-static void dmi_table_dump(u32 base, u16 len, const char *devmem)
|
|
|
3ea658 |
+static void dmi_table_dump(u8 *buf, u16 len)
|
|
|
3ea658 |
{
|
|
|
3ea658 |
- u8 *buf;
|
|
|
3ea658 |
-
|
|
|
3ea658 |
- if ((buf = mem_chunk(base, len, devmem)) == NULL)
|
|
|
3ea658 |
- {
|
|
|
3ea658 |
- fprintf(stderr, "Failed to read table, sorry.\n");
|
|
|
3ea658 |
- return;
|
|
|
3ea658 |
- }
|
|
|
3ea658 |
-
|
|
|
3ea658 |
if (!(opt.flags & FLAG_QUIET))
|
|
|
3ea658 |
printf("# Writing %d bytes to %s.\n", len, opt.dumpfile);
|
|
|
3ea658 |
write_dump(32, len, buf, opt.dumpfile, 0);
|
|
|
3ea658 |
- free(buf);
|
|
|
3ea658 |
}
|
|
|
3ea658 |
|
|
|
3ea658 |
-static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
|
|
|
3ea658 |
+static void dmi_table(u32 base, u8 *buf, u16 len, u16 num, u16 ver)
|
|
|
3ea658 |
{
|
|
|
3ea658 |
- u8 *buf;
|
|
|
3ea658 |
u8 *data;
|
|
|
3ea658 |
int i = 0;
|
|
|
3ea658 |
|
|
|
3ea658 |
@@ -4371,7 +4361,7 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
|
|
|
3ea658 |
|
|
|
3ea658 |
if (opt.flags & FLAG_DUMP_BIN)
|
|
|
3ea658 |
{
|
|
|
3ea658 |
- dmi_table_dump(base, len, devmem);
|
|
|
3ea658 |
+ dmi_table_dump(buf, len);
|
|
|
3ea658 |
return;
|
|
|
3ea658 |
}
|
|
|
3ea658 |
|
|
|
3ea658 |
@@ -4387,16 +4377,6 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
|
|
|
3ea658 |
printf("\n");
|
|
|
3ea658 |
}
|
|
|
3ea658 |
|
|
|
3ea658 |
- if ((buf = mem_chunk(base, len, devmem)) == NULL)
|
|
|
3ea658 |
- {
|
|
|
3ea658 |
- fprintf(stderr, "Table is unreachable, sorry."
|
|
|
3ea658 |
-#ifndef USE_MMAP
|
|
|
3ea658 |
- " Try compiling dmidecode with -DUSE_MMAP."
|
|
|
3ea658 |
-#endif
|
|
|
3ea658 |
- "\n");
|
|
|
3ea658 |
- return;
|
|
|
3ea658 |
- }
|
|
|
3ea658 |
-
|
|
|
3ea658 |
data = buf;
|
|
|
3ea658 |
while (i < num && data+4 <= buf + len) /* 4 is the length of an SMBIOS structure header */
|
|
|
3ea658 |
{
|
|
|
3ea658 |
@@ -4474,8 +4454,6 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
|
|
|
3ea658 |
"announced, structures occupy %d bytes.\n",
|
|
|
3ea658 |
len, (unsigned int)(data - buf));
|
|
|
3ea658 |
}
|
|
|
3ea658 |
-
|
|
|
3ea658 |
- free(buf);
|
|
|
3ea658 |
}
|
|
|
3ea658 |
|
|
|
3ea658 |
/*
|
|
|
3ea658 |
@@ -4513,6 +4491,9 @@ static void smbios_in_dumpfile(unsigned char *smbios)
|
|
|
3ea658 |
static int smbios_decode(u8 *buf, const char *devmem)
|
|
|
3ea658 |
{
|
|
|
3ea658 |
u16 ver;
|
|
|
3ea658 |
+ u16 len;
|
|
|
3ea658 |
+ u32 base;
|
|
|
3ea658 |
+ u8 *dmibuf;
|
|
|
3ea658 |
|
|
|
3ea658 |
if (!checksum(buf, buf[0x05])
|
|
|
3ea658 |
|| memcmp(buf + 0x10, "_DMI_", 5) != 0
|
|
|
3ea658 |
@@ -4521,8 +4502,21 @@ static int smbios_decode(u8 *buf, const char *devmem)
|
|
|
3ea658 |
|
|
|
3ea658 |
ver = get_smbios_version(buf);
|
|
|
3ea658 |
|
|
|
3ea658 |
- dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C),
|
|
|
3ea658 |
- ver, devmem);
|
|
|
3ea658 |
+ base = DWORD(buf + 0x18);
|
|
|
3ea658 |
+ len = WORD(buf + 0x16);
|
|
|
3ea658 |
+ dmibuf = mem_chunk(base, len, devmem);
|
|
|
3ea658 |
+ if (!dmibuf) {
|
|
|
3ea658 |
+ fprintf(stderr, "Table is unreachable, sorry."
|
|
|
3ea658 |
+#ifndef USE_MMAP
|
|
|
3ea658 |
+ " Try compiling dmidecode with -DUSE_MMAP."
|
|
|
3ea658 |
+#endif
|
|
|
3ea658 |
+ "\n");
|
|
|
3ea658 |
+ return 0;
|
|
|
3ea658 |
+ }
|
|
|
3ea658 |
+
|
|
|
3ea658 |
+ dmi_table(base, dmibuf, len, WORD(buf + 0x1C), ver);
|
|
|
3ea658 |
+
|
|
|
3ea658 |
+ free(dmibuf);
|
|
|
3ea658 |
|
|
|
3ea658 |
if (opt.flags & FLAG_DUMP_BIN)
|
|
|
3ea658 |
smbios_in_dumpfile(buf);
|
|
|
3ea658 |
@@ -4532,6 +4526,10 @@ static int smbios_decode(u8 *buf, const char *devmem)
|
|
|
3ea658 |
|
|
|
3ea658 |
static int legacy_decode(u8 *buf, const char *devmem)
|
|
|
3ea658 |
{
|
|
|
3ea658 |
+ u16 len;
|
|
|
3ea658 |
+ u32 base;
|
|
|
3ea658 |
+ u8 *dmibuf;
|
|
|
3ea658 |
+
|
|
|
3ea658 |
if (!checksum(buf, 0x0F))
|
|
|
3ea658 |
return 0;
|
|
|
3ea658 |
|
|
|
3ea658 |
@@ -4539,8 +4537,22 @@ static int legacy_decode(u8 *buf, const char *devmem)
|
|
|
3ea658 |
printf("Legacy DMI %u.%u present.\n",
|
|
|
3ea658 |
buf[0x0E] >> 4, buf[0x0E] & 0x0F);
|
|
|
3ea658 |
|
|
|
3ea658 |
- dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C),
|
|
|
3ea658 |
- ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem);
|
|
|
3ea658 |
+ len = WORD(buf + 0x06);
|
|
|
3ea658 |
+ base = DWORD(buf + 0x08);
|
|
|
3ea658 |
+ dmibuf = mem_chunk(base, len, devmem);
|
|
|
3ea658 |
+ if (!dmibuf) {
|
|
|
3ea658 |
+ fprintf(stderr, "Table is unreachable, sorry."
|
|
|
3ea658 |
+#ifndef USE_MMAP
|
|
|
3ea658 |
+ " Try compiling dmidecode with -DUSE_MMAP."
|
|
|
3ea658 |
+#endif
|
|
|
3ea658 |
+ "\n");
|
|
|
3ea658 |
+ return 0;
|
|
|
3ea658 |
+ }
|
|
|
3ea658 |
+
|
|
|
3ea658 |
+ dmi_table(base, dmibuf, len, WORD(buf + 0x0C),
|
|
|
3ea658 |
+ ((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F));
|
|
|
3ea658 |
+
|
|
|
3ea658 |
+ free(dmibuf);
|
|
|
3ea658 |
|
|
|
3ea658 |
if (opt.flags & FLAG_DUMP_BIN)
|
|
|
3ea658 |
{
|
|
|
3ea658 |
--
|
|
|
3ea658 |
1.9.3
|