From 50021cdb06c3a20a67e968e69a1f0a63af90a263 Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Tue, 20 Mar 2018 12:40:55 -0600 Subject: 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 Change-Id: Ia10ef434a2377e34ae7a8f733c6465c2f8ee8dfa Reviewed-on: https://review.coreboot.org/25302 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin --- src/arch/x86/smbios.c | 56 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'src/arch/x86') 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, -- cgit v1.2.3