]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/base/memory.c
drivers: base: unshare add_memory_section() from hotplug
[karo-tx-linux.git] / drivers / base / memory.c
index e97519bc3d067a9b4f48352aa6c1cc376a5e1a56..2e9a68c646792975ca243889b050c29ecb6cfc9c 100644 (file)
@@ -647,12 +647,25 @@ static int add_memory_section(int nid, struct mem_section *section,
  */
 int register_new_memory(int nid, struct mem_section *section)
 {
-       int ret;
+       int ret = 0;
+       struct memory_block *mem;
 
        mutex_lock(&mem_sysfs_mutex);
-       ret = add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG);
-       mutex_unlock(&mem_sysfs_mutex);
 
+       mem = find_memory_block(section);
+       if (mem) {
+               mem->section_count++;
+               put_device(&mem->dev);
+       } else {
+               ret = init_memory_block(&mem, section, MEM_OFFLINE);
+               if (ret)
+                       goto out;
+       }
+
+       if (mem->section_count == sections_per_block)
+               ret = register_mem_sect_under_node(mem, nid);
+out:
+       mutex_unlock(&mem_sysfs_mutex);
        return ret;
 }