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
This commit is contained in:
Bastien Nocera
2022-03-07 15:33:26 +00:00
committed by Luca Boccassi
parent da637c8fca
commit d48bf01636
4 changed files with 12 additions and 11 deletions
+9 -7
View File
@@ -417,9 +417,9 @@ static void dmi_memory_device_size_detail(
dmi_print_memory_size("MEMORY_DEVICE", attr_suffix, slot_num, code, MEMORY_SIZE_UNIT_BYTES);
}
static void dmi_decode(const struct dmi_header *h) {
static void dmi_decode(const struct dmi_header *h,
unsigned *next_slot_num) {
const uint8_t *data = h->data;
static unsigned next_slot_num = 0;
unsigned slot_num;
/*
@@ -441,15 +441,14 @@ static void dmi_decode(const struct dmi_header *h) {
dmi_print_memory_size("MEMORY_ARRAY", "MAX_CAPACITY", -1, DWORD(data + 0x07), MEMORY_SIZE_UNIT_KB);
else if (h->length >= 0x17)
dmi_print_memory_size("MEMORY_ARRAY", "MAX_CAPACITY", -1, QWORD(data + 0x0F), MEMORY_SIZE_UNIT_BYTES);
printf("MEMORY_ARRAY_NUM_DEVICES=%u\n", WORD(data + 0x0D));
break;
case 17: /* 7.18 Memory Device */
slot_num = next_slot_num;
next_slot_num++;
slot_num = *next_slot_num;
*next_slot_num = slot_num + 1;
log_debug("Memory Device");
log_debug("Memory Device: %u", slot_num);
if (h->length < 0x15)
break;
@@ -525,6 +524,7 @@ static void dmi_decode(const struct dmi_header *h) {
static void dmi_table_decode(const uint8_t *buf, size_t len, uint16_t num) {
const uint8_t *data = buf;
unsigned next_slot_num = 0;
/* 4 is the length of an SMBIOS structure header */
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) {
break;
if (display)
dmi_decode(&h);
dmi_decode(&h, &next_slot_num);
data = next;
}
if (next_slot_num > 0)
printf("MEMORY_ARRAY_NUM_DEVICES=%u\n", next_slot_num);
}
static int dmi_table(int64_t base, uint32_t len, uint16_t num, const char *devmem, bool no_file_offset) {