Blame SOURCES/0023-dmi-avoid-creating-multiple-memory-nodes-700.patch

99c779
From 2afe96801354fdf6bb49d230f357131c6b49fbcc Mon Sep 17 00:00:00 2001
99c779
From: Dan Callaghan <dcallagh@redhat.com>
99c779
Date: Thu, 16 Jul 2015 16:46:44 +1000
99c779
Subject: [PATCH 23/26] dmi: avoid creating multiple memory nodes (#700)
99c779
99c779
The rest of the codebase expects to only find at most one "memory" node,
99c779
even though the SMBIOS data may indicate more than one.
99c779
99c779
If we really do find more than one memory array with type System Memory
99c779
in SMBIOS, we just discard the subsequent ones and place all memory
99c779
devices (DIMMs) into the first memory array.
99c779
---
99c779
 src/core/dmi.cc | 38 ++++++++++++++++++++++++++------------
99c779
 1 file changed, 26 insertions(+), 12 deletions(-)
99c779
99c779
diff --git a/src/core/dmi.cc b/src/core/dmi.cc
99c779
index 8242fed..d5a771d 100644
99c779
--- a/src/core/dmi.cc
99c779
+++ b/src/core/dmi.cc
99c779
@@ -1392,39 +1392,52 @@ int dmiversionmin)
99c779
       case 16:
99c779
 // Physical Memory Array
99c779
         {
99c779
-          hwNode newnode("memory",
99c779
-            hw::memory);
99c779
-          string id = "";
99c779
+          string id = "memory";
99c779
           string description = "";
99c779
+          bool claim = false, memory_icon = false;
99c779
           switch (data[5])
99c779
           {
99c779
             case 0x03:
99c779
               description = _("System Memory");
99c779
-              newnode.claim();
99c779
-              newnode.addHint("icon", string("memory"));
99c779
+              claim = true;
99c779
+              memory_icon = true;
99c779
               break;
99c779
             case 0x04:
99c779
+              id = "videomemory";
99c779
               description = _("Video Memory");
99c779
               break;
99c779
             case 0x05:
99c779
+              id = "flash";
99c779
               description = _("Flash Memory");
99c779
               break;
99c779
             case 0x06:
99c779
+              id = "nvram";
99c779
               description = _("NVRAM");
99c779
               break;
99c779
             case 0x07:
99c779
+              id = "cache";
99c779
               description = _("Cache Memory");
99c779
-              newnode.addHint("icon", string("memory"));
99c779
+              memory_icon = true;
99c779
               break;
99c779
             default:
99c779
               description = _("Generic Memory");
99c779
-              newnode.addHint("icon", string("memory"));
99c779
+              memory_icon = true;
99c779
           }
99c779
-
99c779
+          if (id == "memory" && hardwarenode->getChild("memory"))
99c779
+          {
99c779
+            // we don't want multiple "System memory" nodes,
99c779
+            // so just ignore this one
99c779
+            break;
99c779
+          }
99c779
+          hwNode newnode(id, hw::memory);
99c779
           newnode.setHandle(handle);
99c779
           newnode.setPhysId(dm->handle);
99c779
           newnode.setDescription(description);
99c779
           newnode.setSlot(dmi_memory_array_location(data[4]));
99c779
+          if (memory_icon)
99c779
+            newnode.addHint("icon", string("memory"));
99c779
+          if (claim)
99c779
+            newnode.claim();
99c779
           switch (data[6])
99c779
           {
99c779
             case 0x04:
99c779
@@ -1552,16 +1565,17 @@ int dmiversionmin)
99c779
             newnode.setDescription(newnode.getDescription() + " " + _("[empty]"));
99c779
           newnode.setClock(clock);
99c779
           hwNode *memoryarray = hardwarenode->findChildByHandle(arrayhandle);
99c779
-          if (memoryarray)
99c779
-            memoryarray->addChild(newnode);
99c779
-          else
99c779
+          if (!memoryarray)
99c779
+            memoryarray = hardwarenode->getChild("memory");
99c779
+          if (!memoryarray)
99c779
           {
99c779
             hwNode ramnode("memory",
99c779
               hw::memory);
99c779
-            ramnode.addChild(newnode);
99c779
             ramnode.addHint("icon", string("memory"));
99c779
             hardwarenode->addChild(ramnode);
99c779
+            memoryarray = hardwarenode->getChild("memory");
99c779
           }
99c779
+          memoryarray->addChild(newnode);
99c779
         }
99c779
         break;
99c779
       case 18:
99c779
-- 
99c779
2.10.2
99c779