util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lscpu: add more sanity checks for dmi_decode_cputype()
@ 2021-06-18 12:46 Huang Shijie
  2021-06-18 15:53 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Huang Shijie @ 2021-06-18 12:46 UTC (permalink / raw)
  To: util-linux
  Cc: kzak, patches, zwang, mas, ilkka, jeremy.linton, jbastian,
	m.mizuma, patrick.zhang, Huang Shijie

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>
---
 sys-utils/lscpu-dmi.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
index 782881b75..9b63dd685 100644
--- a/sys-utils/lscpu-dmi.c
+++ b/sys-utils/lscpu-dmi.c
@@ -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);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lscpu: add more sanity checks for dmi_decode_cputype()
  2021-06-18 12:46 [PATCH] lscpu: add more sanity checks for dmi_decode_cputype() Huang Shijie
@ 2021-06-18 15:53 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2021-06-18 15:53 UTC (permalink / raw)
  To: Huang Shijie
  Cc: util-linux, patches, zwang, mas, ilkka, jeremy.linton, jbastian,
	m.mizuma, patrick.zhang

On Fri, Jun 18, 2021 at 12:46:32PM +0000, Huang Shijie wrote:
>  sys-utils/lscpu-dmi.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

Applied, thanks!

 Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-18 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 12:46 [PATCH] lscpu: add more sanity checks for dmi_decode_cputype() Huang Shijie
2021-06-18 15:53 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).