Skip to content

Commit d48bf01

Browse files
hadessbluca
authored andcommitted
memory-id: Work-around incorrect "Number of slots"
In some BIOSes, the "Number of slots or sockets available for Memory Devices in this array" is incorrectly set to the number of memory array that's populated. Work-around this problem by outputting the number of sockets after having parsed them so that consumers of this data can carry on expecting an accurate number in this property. This fixes the number of memory slots advertised for the HP Z600. See https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/1686
1 parent da637c8 commit d48bf01

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/udev/dmi_memory_id/dmi_memory_id.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ static void dmi_memory_device_size_detail(
417417
dmi_print_memory_size("MEMORY_DEVICE", attr_suffix, slot_num, code, MEMORY_SIZE_UNIT_BYTES);
418418
}
419419

420-
static void dmi_decode(const struct dmi_header *h) {
420+
static void dmi_decode(const struct dmi_header *h,
421+
unsigned *next_slot_num) {
421422
const uint8_t *data = h->data;
422-
static unsigned next_slot_num = 0;
423423
unsigned slot_num;
424424

425425
/*
@@ -441,15 +441,14 @@ static void dmi_decode(const struct dmi_header *h) {
441441
dmi_print_memory_size("MEMORY_ARRAY", "MAX_CAPACITY", -1, DWORD(data + 0x07), MEMORY_SIZE_UNIT_KB);
442442
else if (h->length >= 0x17)
443443
dmi_print_memory_size("MEMORY_ARRAY", "MAX_CAPACITY", -1, QWORD(data + 0x0F), MEMORY_SIZE_UNIT_BYTES);
444-
printf("MEMORY_ARRAY_NUM_DEVICES=%u\n", WORD(data + 0x0D));
445444

446445
break;
447446

448447
case 17: /* 7.18 Memory Device */
449-
slot_num = next_slot_num;
450-
next_slot_num++;
448+
slot_num = *next_slot_num;
449+
*next_slot_num = slot_num + 1;
451450

452-
log_debug("Memory Device");
451+
log_debug("Memory Device: %u", slot_num);
453452
if (h->length < 0x15)
454453
break;
455454

@@ -525,6 +524,7 @@ static void dmi_decode(const struct dmi_header *h) {
525524

526525
static void dmi_table_decode(const uint8_t *buf, size_t len, uint16_t num) {
527526
const uint8_t *data = buf;
527+
unsigned next_slot_num = 0;
528528

529529
/* 4 is the length of an SMBIOS structure header */
530530
for (uint16_t i = 0; (i < num || num == 0) && data + 4 <= buf + len; i++) {
@@ -559,10 +559,12 @@ static void dmi_table_decode(const uint8_t *buf, size_t len, uint16_t num) {
559559
break;
560560

561561
if (display)
562-
dmi_decode(&h);
562+
dmi_decode(&h, &next_slot_num);
563563

564564
data = next;
565565
}
566+
if (next_slot_num > 0)
567+
printf("MEMORY_ARRAY_NUM_DEVICES=%u\n", next_slot_num);
566568
}
567569

568570
static int dmi_table(int64_t base, uint32_t len, uint16_t num, const char *devmem, bool no_file_offset) {

test/dmidecode-dumps/HP-Z600.bin.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
MEMORY_ARRAY_LOCATION=System Board Or Motherboard
22
MEMORY_ARRAY_EC_TYPE=Multi-bit ECC
33
MEMORY_ARRAY_MAX_CAPACITY=12884901888
4-
MEMORY_ARRAY_NUM_DEVICES=3
54
MEMORY_ARRAY_LOCATION=System Board Or Motherboard
65
MEMORY_ARRAY_EC_TYPE=Multi-bit ECC
76
MEMORY_ARRAY_MAX_CAPACITY=12884901888
8-
MEMORY_ARRAY_NUM_DEVICES=3
97
MEMORY_DEVICE_0_TOTAL_WIDTH=72
108
MEMORY_DEVICE_0_DATA_WIDTH=64
119
MEMORY_DEVICE_0_SIZE=8589934592
@@ -92,3 +90,4 @@ MEMORY_DEVICE_6_MANUFACTURER=Not Specified
9290
MEMORY_DEVICE_6_SERIAL_NUMBER=Not Specified
9391
MEMORY_DEVICE_6_ASSET_TAG=Not Specified
9492
MEMORY_DEVICE_6_PART_NUMBER=Not Specified
93+
MEMORY_ARRAY_NUM_DEVICES=7

test/dmidecode-dumps/Lenovo-ThinkPad-X280.bin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
MEMORY_ARRAY_LOCATION=System Board Or Motherboard
22
MEMORY_ARRAY_MAX_CAPACITY=34359738368
3-
MEMORY_ARRAY_NUM_DEVICES=2
43
MEMORY_DEVICE_0_TOTAL_WIDTH=64
54
MEMORY_DEVICE_0_DATA_WIDTH=64
65
MEMORY_DEVICE_0_SIZE=4294967296
@@ -31,3 +30,4 @@ MEMORY_DEVICE_1_ASSET_TAG=None
3130
MEMORY_DEVICE_1_RANK=1
3231
MEMORY_DEVICE_1_CONFIGURED_SPEED_MTS=2400
3332
MEMORY_DEVICE_1_CONFIGURED_VOLTAGE=1
33+
MEMORY_ARRAY_NUM_DEVICES=2

test/dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
MEMORY_ARRAY_LOCATION=System Board Or Motherboard
22
MEMORY_ARRAY_MAX_CAPACITY=68719476736
3-
MEMORY_ARRAY_NUM_DEVICES=4
43
MEMORY_DEVICE_0_TOTAL_WIDTH=64
54
MEMORY_DEVICE_0_DATA_WIDTH=64
65
MEMORY_DEVICE_0_SIZE=8589934592
@@ -65,3 +64,4 @@ MEMORY_DEVICE_3_CONFIGURED_SPEED_MTS=2400
6564
MEMORY_DEVICE_3_MINIMUM_VOLTAGE=1
6665
MEMORY_DEVICE_3_MAXIMUM_VOLTAGE=1
6766
MEMORY_DEVICE_3_CONFIGURED_VOLTAGE=1
67+
MEMORY_ARRAY_NUM_DEVICES=4

0 commit comments

Comments
 (0)