lscpu: add more sanity checks for dmi_decode_cputype()

After tested on different platforms, we found dmi_string() may return NULL
in some case.

So add more sanity checks for dmi_decode_cputype().

Signed-off-by: Huang Shijie <shijie@os.amperecomputing.com>
This commit is contained in:
Huang Shijie 2021-06-18 12:46:32 +00:00 committed by Karel Zak
parent 6eb184299e
commit b366e69b82
1 changed files with 4 additions and 3 deletions

View File

@ -115,10 +115,11 @@ int dmi_decode_cputype(struct lscpu_cputype *ct)
return rc;
}
ct->bios_vendor = xstrdup(di.processor_manufacturer);
if (di.processor_manufacturer)
ct->bios_vendor = xstrdup(di.processor_manufacturer);
snprintf(buf, sizeof(buf),
"%s %s CPU @ %d.%dGHz", di.processor_version, di.part_num,
snprintf(buf, sizeof(buf), "%s %s CPU @ %d.%dGHz",
(di.processor_version ?: ""), (di.part_num ?: ""),
di.current_speed/1000, (di.current_speed % 1000) / 100);
ct->bios_modelname = xstrdup(buf);