Skip to content

Commit fe3a5a0

Browse files
committed
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.
1 parent e604a9e commit fe3a5a0

File tree

4 files changed

+61
-49
lines changed

4 files changed

+61
-49
lines changed

dmidecode.c

+39-21
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static void dmi_bios_characteristics_x2(u8 code, const char *prefix)
299299
* 3.3.2 System Information (Type 1)
300300
*/
301301

302-
void dmi_system_uuid(u8 *p, u16 ver)
302+
static void dmi_system_uuid(const u8 *p, u16 ver)
303303
{
304304
int only0xFF = 1, only0x00 = 1;
305305
int i;
@@ -427,7 +427,7 @@ static void dmi_base_board_handles(u8 count, u8 *p, const char *prefix)
427427
* 3.3.4 Chassis Information (Type 3)
428428
*/
429429

430-
const char *dmi_chassis_type(u16 code)
430+
static const char *dmi_chassis_type(u8 code)
431431
{
432432
/* 3.3.4.1 */
433433
static const char *type[] = {
@@ -570,7 +570,7 @@ static const char *dmi_processor_type(u8 code)
570570
return out_of_spec;
571571
}
572572

573-
const char *dmi_processor_family(u16 code)
573+
static const char *dmi_processor_family(u16 code)
574574
{
575575
unsigned int i;
576576

@@ -893,10 +893,9 @@ static void dmi_processor_voltage(u8 code)
893893
}
894894
}
895895

896-
void dmi_processor_frequency(u8 *p, u16 ver)
896+
static void dmi_processor_frequency(const u8 *p)
897897
{
898898
u16 code = WORD(p);
899-
(void) ver;
900899

901900
if (code)
902901
printf("%u MHz", code);
@@ -2930,13 +2929,13 @@ static void dmi_decode(struct dmi_header *h, u16 ver)
29302929
dmi_processor_voltage(data[0x11]);
29312930
printf("\n");
29322931
printf("\tExternal Clock: ");
2933-
dmi_processor_frequency(data + 0x12, ver);
2932+
dmi_processor_frequency(data + 0x12);
29342933
printf("\n");
29352934
printf("\tMax Speed: ");
2936-
dmi_processor_frequency(data + 0x14, ver);
2935+
dmi_processor_frequency(data + 0x14);
29372936
printf("\n");
29382937
printf("\tCurrent Speed: ");
2939-
dmi_processor_frequency(data + 0x16, ver);
2938+
dmi_processor_frequency(data + 0x16);
29402939
printf("\n");
29412940
if (data[0x18]&(1<<6))
29422941
printf("\tStatus: Populated, %s\n",
@@ -3762,6 +3761,36 @@ static void to_dmi_header(struct dmi_header *h, u8 *data)
37623761
h->data = data;
37633762
}
37643763

3764+
static void dmi_table_string(struct dmi_header *h, const u8 *data, u16 ver)
3765+
{
3766+
int key;
3767+
u8 offset = opt.string->offset;
3768+
3769+
if (offset >= h->length)
3770+
return;
3771+
3772+
key = (opt.string->type << 8) | offset;
3773+
switch (key)
3774+
{
3775+
case 0x108:
3776+
dmi_system_uuid(data + offset, ver);
3777+
printf("\n");
3778+
break;
3779+
case 0x305:
3780+
printf("%s\n", dmi_chassis_type(data[offset]));
3781+
break;
3782+
case 0x406:
3783+
printf("%s\n", dmi_processor_family(data[offset]));
3784+
break;
3785+
case 0x416:
3786+
dmi_processor_frequency(data + offset);
3787+
printf("\n");
3788+
break;
3789+
default:
3790+
printf("%s\n", dmi_string(h, data[offset]));
3791+
}
3792+
}
3793+
37653794
static void dmi_table_dump(u32 base, u16 len, const char *devmem)
37663795
{
37673796
u8 *buf;
@@ -3870,19 +3899,8 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
38703899
printf("\t<TRUNCATED>\n\n");
38713900
}
38723901
else if (opt.string != NULL
3873-
&& opt.string->type == h.type
3874-
&& opt.string->offset < h.length)
3875-
{
3876-
if (opt.string->lookup != NULL)
3877-
printf("%s\n", opt.string->lookup(data[opt.string->offset]));
3878-
else if (opt.string->print != NULL)
3879-
{
3880-
opt.string->print(data + opt.string->offset, ver);
3881-
printf("\n");
3882-
}
3883-
else
3884-
printf("%s\n", dmi_string(&h, data[opt.string->offset]));
3885-
}
3902+
&& opt.string->type == h.type)
3903+
dmi_table_string(&h, data, ver);
38863904

38873905
data = next;
38883906
i++;

dmidecode.h

-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,3 @@ struct dmi_header
2727
};
2828

2929
const char *dmi_string(struct dmi_header *dm, u8 s);
30-
void dmi_system_uuid(u8 *p, u16 ver);
31-
const char *dmi_chassis_type(u16 code);
32-
const char *dmi_processor_family(u16 code);
33-
void dmi_processor_frequency(u8 *p, u16 ver);

dmiopt.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,28 @@ static u8 *parse_opt_type(u8 *p, const char *arg)
147147
Due to the low count of items in there at the moment, it did not seem
148148
worth the additional code complexity though. */
149149
static const struct string_keyword opt_string_keyword[] = {
150-
{ "bios-vendor", 0, 0x04, NULL, NULL },
151-
{ "bios-version", 0, 0x05, NULL, NULL },
152-
{ "bios-release-date", 0, 0x08, NULL, NULL },
153-
{ "system-manufacturer", 1, 0x04, NULL, NULL },
154-
{ "system-product-name", 1, 0x05, NULL, NULL },
155-
{ "system-version", 1, 0x06, NULL, NULL },
156-
{ "system-serial-number", 1, 0x07, NULL, NULL },
157-
{ "system-uuid", 1, 0x08, NULL, dmi_system_uuid },
158-
{ "baseboard-manufacturer", 2, 0x04, NULL, NULL },
159-
{ "baseboard-product-name", 2, 0x05, NULL, NULL },
160-
{ "baseboard-version", 2, 0x06, NULL, NULL },
161-
{ "baseboard-serial-number", 2, 0x07, NULL, NULL },
162-
{ "baseboard-asset-tag", 2, 0x08, NULL, NULL },
163-
{ "chassis-manufacturer", 3, 0x04, NULL, NULL },
164-
{ "chassis-type", 3, 0x05, dmi_chassis_type, NULL },
165-
{ "chassis-version", 3, 0x06, NULL, NULL },
166-
{ "chassis-serial-number", 3, 0x07, NULL, NULL },
167-
{ "chassis-asset-tag", 3, 0x08, NULL, NULL },
168-
{ "processor-family", 4, 0x06, dmi_processor_family, NULL },
169-
{ "processor-manufacturer", 4, 0x07, NULL, NULL },
170-
{ "processor-version", 4, 0x10, NULL, NULL },
171-
{ "processor-frequency", 4, 0x16, NULL, dmi_processor_frequency },
150+
{ "bios-vendor", 0, 0x04 },
151+
{ "bios-version", 0, 0x05 },
152+
{ "bios-release-date", 0, 0x08 },
153+
{ "system-manufacturer", 1, 0x04 },
154+
{ "system-product-name", 1, 0x05 },
155+
{ "system-version", 1, 0x06 },
156+
{ "system-serial-number", 1, 0x07 },
157+
{ "system-uuid", 1, 0x08 }, /* dmi_system_uuid() */
158+
{ "baseboard-manufacturer", 2, 0x04 },
159+
{ "baseboard-product-name", 2, 0x05 },
160+
{ "baseboard-version", 2, 0x06 },
161+
{ "baseboard-serial-number", 2, 0x07 },
162+
{ "baseboard-asset-tag", 2, 0x08 },
163+
{ "chassis-manufacturer", 3, 0x04 },
164+
{ "chassis-type", 3, 0x05 }, /* dmi_chassis_type() */
165+
{ "chassis-version", 3, 0x06 },
166+
{ "chassis-serial-number", 3, 0x07 },
167+
{ "chassis-asset-tag", 3, 0x08 },
168+
{ "processor-family", 4, 0x06 }, /* dmi_processor_family() */
169+
{ "processor-manufacturer", 4, 0x07 },
170+
{ "processor-version", 4, 0x10 },
171+
{ "processor-frequency", 4, 0x16 }, /* dmi_processor_frequency() */
172172
};
173173

174174
static void print_opt_string_list(void)

dmiopt.h

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ struct string_keyword
2424
const char *keyword;
2525
u8 type;
2626
u8 offset;
27-
const char *(*lookup)(u16);
28-
void (*print)(u8 *, u16);
2927
};
3028

3129
struct opt

0 commit comments

Comments
 (0)