Skip to content

Commit cb5e39b

Browse files
Seth Jenningsgregkh
authored andcommitted
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>
1 parent 37171e3 commit cb5e39b

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

drivers/base/memory.c

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -602,32 +602,31 @@ static int init_memory_block(struct memory_block **memory,
602602
return ret;
603603
}
604604

605-
static int add_memory_section(struct mem_section *section,
606-
struct memory_block **mem_p)
605+
static int add_memory_block(int base_section_nr)
607606
{
608-
struct memory_block *mem = NULL;
609-
int scn_nr = __section_nr(section);
610-
int ret = 0;
611-
612-
if (mem_p && *mem_p) {
613-
if (scn_nr >= (*mem_p)->start_section_nr &&
614-
scn_nr <= (*mem_p)->end_section_nr) {
615-
mem = *mem_p;
616-
}
617-
}
607+
struct memory_block *mem;
608+
int i, ret, section_count = 0, section_nr;
618609

619-
if (mem)
620-
mem->section_count++;
621-
else {
622-
ret = init_memory_block(&mem, section, MEM_ONLINE);
623-
/* store memory_block pointer for next loop */
624-
if (!ret && mem_p)
625-
*mem_p = mem;
610+
for (i = base_section_nr;
611+
(i < base_section_nr + sections_per_block) && i < NR_MEM_SECTIONS;
612+
i++) {
613+
if (!present_section_nr(i))
614+
continue;
615+
if (section_count == 0)
616+
section_nr = i;
617+
section_count++;
626618
}
627619

628-
return ret;
620+
if (section_count == 0)
621+
return 0;
622+
ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE);
623+
if (ret)
624+
return ret;
625+
mem->section_count = section_count;
626+
return 0;
629627
}
630628

629+
631630
/*
632631
* need an interface for the VM to add new memory regions,
633632
* but without onlining it.
@@ -733,7 +732,6 @@ int __init memory_dev_init(void)
733732
int ret;
734733
int err;
735734
unsigned long block_sz;
736-
struct memory_block *mem = NULL;
737735

738736
ret = subsys_system_register(&memory_subsys, memory_root_attr_groups);
739737
if (ret)
@@ -747,12 +745,8 @@ int __init memory_dev_init(void)
747745
* during boot and have been initialized
748746
*/
749747
mutex_lock(&mem_sysfs_mutex);
750-
for (i = 0; i < NR_MEM_SECTIONS; i++) {
751-
if (!present_section_nr(i))
752-
continue;
753-
/* don't need to reuse memory_block if only one per block */
754-
err = add_memory_section(__nr_to_section(i),
755-
(sections_per_block == 1) ? NULL : &mem);
748+
for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) {
749+
err = add_memory_block(i);
756750
if (!ret)
757751
ret = err;
758752
}

0 commit comments

Comments
 (0)