drivers: base: refactor add_memory_section() to add_memory_block()
Right now memory_dev_init() maintains the memory block pointer between iterations of add_memory_section(). This is nasty. This patch refactors add_memory_section() to become add_memory_block(). The refactoring pulls the section scanning out of memory_dev_init() and simplifies the signature. Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
37171e3cb7
commit
cb5e39b803
1 changed files with 21 additions and 27 deletions
|
@ -602,32 +602,31 @@ static int init_memory_block(struct memory_block **memory,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_memory_section(struct mem_section *section,
|
static int add_memory_block(int base_section_nr)
|
||||||
struct memory_block **mem_p)
|
|
||||||
{
|
{
|
||||||
struct memory_block *mem = NULL;
|
struct memory_block *mem;
|
||||||
int scn_nr = __section_nr(section);
|
int i, ret, section_count = 0, section_nr;
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (mem_p && *mem_p) {
|
for (i = base_section_nr;
|
||||||
if (scn_nr >= (*mem_p)->start_section_nr &&
|
(i < base_section_nr + sections_per_block) && i < NR_MEM_SECTIONS;
|
||||||
scn_nr <= (*mem_p)->end_section_nr) {
|
i++) {
|
||||||
mem = *mem_p;
|
if (!present_section_nr(i))
|
||||||
}
|
continue;
|
||||||
|
if (section_count == 0)
|
||||||
|
section_nr = i;
|
||||||
|
section_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mem)
|
if (section_count == 0)
|
||||||
mem->section_count++;
|
return 0;
|
||||||
else {
|
ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE);
|
||||||
ret = init_memory_block(&mem, section, MEM_ONLINE);
|
if (ret)
|
||||||
/* store memory_block pointer for next loop */
|
return ret;
|
||||||
if (!ret && mem_p)
|
mem->section_count = section_count;
|
||||||
*mem_p = mem;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* need an interface for the VM to add new memory regions,
|
* need an interface for the VM to add new memory regions,
|
||||||
* but without onlining it.
|
* but without onlining it.
|
||||||
|
@ -733,7 +732,6 @@ int __init memory_dev_init(void)
|
||||||
int ret;
|
int ret;
|
||||||
int err;
|
int err;
|
||||||
unsigned long block_sz;
|
unsigned long block_sz;
|
||||||
struct memory_block *mem = NULL;
|
|
||||||
|
|
||||||
ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);
|
ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -747,12 +745,8 @@ int __init memory_dev_init(void)
|
||||||
* during boot and have been initialized
|
* during boot and have been initialized
|
||||||
*/
|
*/
|
||||||
mutex_lock(&mem_sysfs_mutex);
|
mutex_lock(&mem_sysfs_mutex);
|
||||||
for (i = 0; i < NR_MEM_SECTIONS; i++) {
|
for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) {
|
||||||
if (!present_section_nr(i))
|
err = add_memory_block(i);
|
||||||
continue;
|
|
||||||
/* don't need to reuse memory_block if only one per block */
|
|
||||||
err = add_memory_section(__nr_to_section(i),
|
|
||||||
(sections_per_block == 1) ? NULL : &mem);
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = err;
|
ret = err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue