From 9ce09ccc3c8eee9be4fb5f33ae382d92c69dc411 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Wed, 20 Mar 2024 14:42:28 +0100
Subject: [PATCH] lscpu: don't use NULL sharedmap

Fixes: https://github.com/util-linux/util-linux/issues/2846
Signed-off-by: Karel Zak <kzak@redhat.com>
---
 sys-utils/lscpu-topology.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys-utils/lscpu-topology.c b/sys-utils/lscpu-topology.c
index 7ee18e785..e3742e319 100644
--- a/sys-utils/lscpu-topology.c
+++ b/sys-utils/lscpu-topology.c
@@ -253,7 +253,8 @@ struct lscpu_cache *lscpu_cpu_get_cache(struct lscpu_cxt *cxt,
 	for (i = 0; i < cxt->ncaches; i++) {
 		struct lscpu_cache *ca = &cxt->caches[i];
 
-		if (strcmp(ca->name, name) == 0 &&
+		if (ca->sharedmap &&
+		    strcmp(ca->name, name) == 0 &&
 		    CPU_ISSET_S(cpu->logical_id, cxt->setsize, ca->sharedmap))
 			return ca;
 	}
-- 
2.33.0

