summaryrefslogtreecommitdiff
path: root/src/arch/x86/smbios.c
diff options
context:
space:
mode:
authorRaul E Rangel <rrangel@chromium.org>2018-03-20 12:40:55 -0600
committerAaron Durbin <adurbin@chromium.org>2018-03-23 15:33:16 +0000
commit50021cdb06c3a20a67e968e69a1f0a63af90a263 (patch)
tree01dc3fe17f96a94e46425c6f1c6f62fdb5f84bad /src/arch/x86/smbios.c
parent5041e9b416a26c338eca25572452b62fd512956b (diff)
arch/x86/smbios: Strip trailing whitespace on DMI 17 part number.
dmidecode used to print 'HMAA51S6AMR6N-UH ' it now prints 'HMAA51S6AMR6N-UH' BUG=b:65403853 TEST=Verified using dmidecode Signed-off-by: Raul E Rangel <rrangel@chromium.org> Change-Id: Ia10ef434a2377e34ae7a8f733c6465c2f8ee8dfa Reviewed-on: https://review.coreboot.org/25302 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/arch/x86/smbios.c')
-rw-r--r--src/arch/x86/smbios.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c
index 85851c60cb..70793741fa 100644
--- a/src/arch/x86/smbios.c
+++ b/src/arch/x86/smbios.c
@@ -195,28 +195,60 @@ void smbios_fill_dimm_manufacturer_from_id(uint16_t mod_id,
}
}
-/* This function will fill the corresponding part number */
-static void smbios_fill_dimm_part_number(char *part_number,
- struct smbios_type17 *t)
+static void trim_trailing_whitespace(char *buffer, size_t buffer_size)
{
- int i, invalid;
+ size_t len = strnlen(buffer, buffer_size);
+
+ if (len == 0)
+ return;
+
+ for (char *p = buffer + len - 1; p >= buffer; --p) {
+ if (*p == ' ')
+ *p = 0;
+ else
+ break;
+ }
+}
+
+/** This function will fill the corresponding part number */
+static void smbios_fill_dimm_part_number(const char *part_number,
+ struct smbios_type17 *t)
+{
+ const size_t trimmed_buffer_size = DIMM_INFO_PART_NUMBER_SIZE;
+
+ int invalid;
+ size_t i, len;
+ char trimmed_part_number[trimmed_buffer_size];
+
+ strncpy(trimmed_part_number, part_number, trimmed_buffer_size);
+ trimmed_part_number[trimmed_buffer_size - 1] = '\0';
+
+ /*
+ * SPD mandates that unused characters be represented with a ' '.
+ * We don't want to publish the whitespace in the SMBIOS tables.
+ */
+ trim_trailing_whitespace(trimmed_part_number, trimmed_buffer_size);
+
+ len = strlen(trimmed_part_number);
invalid = 0; /* assume valid */
- for (i = 0; i < DIMM_INFO_PART_NUMBER_SIZE - 1; i++) {
- if (part_number[i] < ' ') {
+ for (i = 0; i < len - 1; i++) {
+ if (trimmed_part_number[i] < ' ') {
invalid = 1;
- part_number[i] = '*';
+ trimmed_part_number[i] = '*';
}
}
+
if (invalid) {
- char string_buffer[64];
+ char string_buffer[trimmed_buffer_size +
+ 10 /* strlen("Invalid ()") */];
snprintf(string_buffer, sizeof(string_buffer), "Invalid (%s)",
- part_number);
+ trimmed_part_number);
t->part_number = smbios_add_string(t->eos, string_buffer);
- } else
- t->part_number = smbios_add_string(t->eos, part_number);
-
+ } else {
+ t->part_number = smbios_add_string(t->eos, trimmed_part_number);
+ }
}
static int create_smbios_type17_for_dimm(struct dimm_info *dimm,