summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkhali <khali>2008-10-28 09:03:34 +0000
committerkhali <khali>2008-10-28 09:03:34 +0000
commit674531b74b0a11324ae96e277aff271bea7944be (patch)
tree716076a8fabc995255b40d442f71720664522aeb
parent56bfc2c4ce8aa36e64145bf8ca33f5485a13b011 (diff)
downloaddmidecode-674531b74b0a11324ae96e277aff271bea7944be.tar.gz
Don't use function pointers for special string cases. Each special case is
itself special and needs to call a function with its own prototype, so better have dedicated code to handle it all.
-rw-r--r--dmidecode.c60
-rw-r--r--dmidecode.h4
-rw-r--r--dmiopt.c44
-rw-r--r--dmiopt.h2
4 files changed, 61 insertions, 49 deletions
diff --git a/dmidecode.c b/dmidecode.c
index 3f5b3c2..6bb68f4 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -299,7 +299,7 @@ static void dmi_bios_characteristics_x2(u8 code, const char *prefix)
* 3.3.2 System Information (Type 1)
*/
-void dmi_system_uuid(u8 *p, u16 ver)
+static void dmi_system_uuid(const u8 *p, u16 ver)
{
int only0xFF = 1, only0x00 = 1;
int i;
@@ -427,7 +427,7 @@ static void dmi_base_board_handles(u8 count, u8 *p, const char *prefix)
* 3.3.4 Chassis Information (Type 3)
*/
-const char *dmi_chassis_type(u16 code)
+static const char *dmi_chassis_type(u8 code)
{
/* 3.3.4.1 */
static const char *type[] = {
@@ -570,7 +570,7 @@ static const char *dmi_processor_type(u8 code)
return out_of_spec;
}
-const char *dmi_processor_family(u16 code)
+static const char *dmi_processor_family(u16 code)
{
unsigned int i;
@@ -893,10 +893,9 @@ static void dmi_processor_voltage(u8 code)
}
}
-void dmi_processor_frequency(u8 *p, u16 ver)
+static void dmi_processor_frequency(const u8 *p)
{
u16 code = WORD(p);
- (void) ver;
if (code)
printf("%u MHz", code);
@@ -2930,13 +2929,13 @@ static void dmi_decode(struct dmi_header *h, u16 ver)
dmi_processor_voltage(data[0x11]);
printf("\n");
printf("\tExternal Clock: ");
- dmi_processor_frequency(data + 0x12, ver);
+ dmi_processor_frequency(data + 0x12);
printf("\n");
printf("\tMax Speed: ");
- dmi_processor_frequency(data + 0x14, ver);
+ dmi_processor_frequency(data + 0x14);
printf("\n");
printf("\tCurrent Speed: ");
- dmi_processor_frequency(data + 0x16, ver);
+ dmi_processor_frequency(data + 0x16);
printf("\n");
if (data[0x18]&(1<<6))
printf("\tStatus: Populated, %s\n",
@@ -3762,6 +3761,36 @@ static void to_dmi_header(struct dmi_header *h, u8 *data)
h->data = data;
}
+static void dmi_table_string(struct dmi_header *h, const u8 *data, u16 ver)
+{
+ int key;
+ u8 offset = opt.string->offset;
+
+ if (offset >= h->length)
+ return;
+
+ key = (opt.string->type << 8) | offset;
+ switch (key)
+ {
+ case 0x108:
+ dmi_system_uuid(data + offset, ver);
+ printf("\n");
+ break;
+ case 0x305:
+ printf("%s\n", dmi_chassis_type(data[offset]));
+ break;
+ case 0x406:
+ printf("%s\n", dmi_processor_family(data[offset]));
+ break;
+ case 0x416:
+ dmi_processor_frequency(data + offset);
+ printf("\n");
+ break;
+ default:
+ printf("%s\n", dmi_string(h, data[offset]));
+ }
+}
+
static void dmi_table_dump(u32 base, u16 len, const char *devmem)
{
u8 *buf;
@@ -3870,19 +3899,8 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
printf("\t<TRUNCATED>\n\n");
}
else if (opt.string != NULL
- && opt.string->type == h.type
- && opt.string->offset < h.length)
- {
- if (opt.string->lookup != NULL)
- printf("%s\n", opt.string->lookup(data[opt.string->offset]));
- else if (opt.string->print != NULL)
- {
- opt.string->print(data + opt.string->offset, ver);
- printf("\n");
- }
- else
- printf("%s\n", dmi_string(&h, data[opt.string->offset]));
- }
+ && opt.string->type == h.type)
+ dmi_table_string(&h, data, ver);
data = next;
i++;
diff --git a/dmidecode.h b/dmidecode.h
index 4d287d2..ae284f7 100644
--- a/dmidecode.h
+++ b/dmidecode.h
@@ -27,7 +27,3 @@ struct dmi_header
};
const char *dmi_string(struct dmi_header *dm, u8 s);
-void dmi_system_uuid(u8 *p, u16 ver);
-const char *dmi_chassis_type(u16 code);
-const char *dmi_processor_family(u16 code);
-void dmi_processor_frequency(u8 *p, u16 ver);
diff --git a/dmiopt.c b/dmiopt.c
index 1aea8e5..32053d9 100644
--- a/dmiopt.c
+++ b/dmiopt.c
@@ -147,28 +147,28 @@ exit_free:
Due to the low count of items in there at the moment, it did not seem
worth the additional code complexity though. */
static const struct string_keyword opt_string_keyword[] = {
- { "bios-vendor", 0, 0x04, NULL, NULL },
- { "bios-version", 0, 0x05, NULL, NULL },
- { "bios-release-date", 0, 0x08, NULL, NULL },
- { "system-manufacturer", 1, 0x04, NULL, NULL },
- { "system-product-name", 1, 0x05, NULL, NULL },
- { "system-version", 1, 0x06, NULL, NULL },
- { "system-serial-number", 1, 0x07, NULL, NULL },
- { "system-uuid", 1, 0x08, NULL, dmi_system_uuid },
- { "baseboard-manufacturer", 2, 0x04, NULL, NULL },
- { "baseboard-product-name", 2, 0x05, NULL, NULL },
- { "baseboard-version", 2, 0x06, NULL, NULL },
- { "baseboard-serial-number", 2, 0x07, NULL, NULL },
- { "baseboard-asset-tag", 2, 0x08, NULL, NULL },
- { "chassis-manufacturer", 3, 0x04, NULL, NULL },
- { "chassis-type", 3, 0x05, dmi_chassis_type, NULL },
- { "chassis-version", 3, 0x06, NULL, NULL },
- { "chassis-serial-number", 3, 0x07, NULL, NULL },
- { "chassis-asset-tag", 3, 0x08, NULL, NULL },
- { "processor-family", 4, 0x06, dmi_processor_family, NULL },
- { "processor-manufacturer", 4, 0x07, NULL, NULL },
- { "processor-version", 4, 0x10, NULL, NULL },
- { "processor-frequency", 4, 0x16, NULL, dmi_processor_frequency },
+ { "bios-vendor", 0, 0x04 },
+ { "bios-version", 0, 0x05 },
+ { "bios-release-date", 0, 0x08 },
+ { "system-manufacturer", 1, 0x04 },
+ { "system-product-name", 1, 0x05 },
+ { "system-version", 1, 0x06 },
+ { "system-serial-number", 1, 0x07 },
+ { "system-uuid", 1, 0x08 }, /* dmi_system_uuid() */
+ { "baseboard-manufacturer", 2, 0x04 },
+ { "baseboard-product-name", 2, 0x05 },
+ { "baseboard-version", 2, 0x06 },
+ { "baseboard-serial-number", 2, 0x07 },
+ { "baseboard-asset-tag", 2, 0x08 },
+ { "chassis-manufacturer", 3, 0x04 },
+ { "chassis-type", 3, 0x05 }, /* dmi_chassis_type() */
+ { "chassis-version", 3, 0x06 },
+ { "chassis-serial-number", 3, 0x07 },
+ { "chassis-asset-tag", 3, 0x08 },
+ { "processor-family", 4, 0x06 }, /* dmi_processor_family() */
+ { "processor-manufacturer", 4, 0x07 },
+ { "processor-version", 4, 0x10 },
+ { "processor-frequency", 4, 0x16 }, /* dmi_processor_frequency() */
};
static void print_opt_string_list(void)
diff --git a/dmiopt.h b/dmiopt.h
index 0882154..17f1849 100644
--- a/dmiopt.h
+++ b/dmiopt.h
@@ -24,8 +24,6 @@ struct string_keyword
const char *keyword;
u8 type;
u8 offset;
- const char *(*lookup)(u16);
- void (*print)(u8 *, u16);
};
struct opt