diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 5185bcff2de91f5216decd1c4614e9f1ab123cf1..cafeaaf0428fc5ef59a622b5671c252e7b77b1a4 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -490,6 +490,7 @@ static int add_memory_block(int nid, struct mem_section *section, mem->phys_index = __section_nr(section); mem->state = state; + mem->section_count++; mutex_init(&mem->state_mutex); start_pfn = section_nr_to_pfn(mem->phys_index); mem->phys_device = arch_get_memory_phys_device(start_pfn); @@ -519,12 +520,16 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section, mutex_lock(&mem_sysfs_mutex); mem = find_memory_block(section); - unregister_mem_sect_under_nodes(mem); - mem_remove_simple_file(mem, phys_index); - mem_remove_simple_file(mem, state); - mem_remove_simple_file(mem, phys_device); - mem_remove_simple_file(mem, removable); - unregister_memory(mem, section); + + mem->section_count--; + if (mem->section_count == 0) { + unregister_mem_sect_under_nodes(mem); + mem_remove_simple_file(mem, phys_index); + mem_remove_simple_file(mem, state); + mem_remove_simple_file(mem, phys_device); + mem_remove_simple_file(mem, removable); + unregister_memory(mem, section); + } mutex_unlock(&mem_sysfs_mutex); return 0; diff --git a/include/linux/memory.h b/include/linux/memory.h index c4f3127dbd4807f4a23f740125c6a2886fcde551..06c1fa0a5c7b5a4fb908a01f59699e5d1f1d77cc 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -23,6 +23,8 @@ struct memory_block { unsigned long phys_index; unsigned long state; + int section_count; + /* * This serializes all state change requests. It isn't * held during creation because the control files are