Skip to content

Commit 1811582

Browse files
David Hildenbrandtorvalds
authored andcommitted
drivers/base/memory: pass a block_id to init_memory_block()
We'll rework hotplug_memory_register() shortly, so it no longer consumes pass a section. [cai@lca.pw: fix a compilation warning] Link: http://lkml.kernel.org/r/1559320186-28337-1-git-send-email-cai@lca.pw Link: http://lkml.kernel.org/r/20190527111152.16324-6-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Qian Cai <cai@lca.pw> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: Andrew Banman <andrew.banman@hpe.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Arun KS <arunks@codeaurora.org> Cc: Baoquan He <bhe@redhat.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chintan Pandya <cpandya@codeaurora.org> Cc: Christophe Leroy <christophe.leroy@c-s.fr> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Jun Yao <yaojun8558363@gmail.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Cc: Logan Gunthorpe <logang@deltatee.com> Cc: Mark Brown <broonie@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Mathieu Malaterre <malat@debian.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: "mike.travis@hpe.com" <mike.travis@hpe.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Oscar Salvador <osalvador@suse.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rich Felker <dalias@libc.org> Cc: Rob Herring <robh@kernel.org> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Yu Zhao <yuzhao@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 22eb634 commit 1811582

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

‎drivers/base/memory.c‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,18 @@ int register_memory(struct memory_block *memory)
651651
return ret;
652652
}
653653

654-
static int init_memory_block(struct memory_block **memory,
655-
struct mem_section *section, unsigned long state)
654+
static int init_memory_block(struct memory_block **memory, int block_id,
655+
unsigned long state)
656656
{
657657
struct memory_block *mem;
658658
unsigned long start_pfn;
659-
int scn_nr;
660659
int ret = 0;
661660

662661
mem = kzalloc(sizeof(*mem), GFP_KERNEL);
663662
if (!mem)
664663
return -ENOMEM;
665664

666-
scn_nr = __section_nr(section);
667-
mem->start_section_nr =
668-
base_memory_block_id(scn_nr) * sections_per_block;
665+
mem->start_section_nr = block_id * sections_per_block;
669666
mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
670667
mem->state = state;
671668
start_pfn = section_nr_to_pfn(mem->start_section_nr);
@@ -680,21 +677,18 @@ static int init_memory_block(struct memory_block **memory,
680677
static int add_memory_block(int base_section_nr)
681678
{
682679
struct memory_block *mem;
683-
int i, ret, section_count = 0, section_nr;
680+
int i, ret, section_count = 0;
684681

685682
for (i = base_section_nr;
686683
i < base_section_nr + sections_per_block;
687-
i++) {
688-
if (!present_section_nr(i))
689-
continue;
690-
if (section_count == 0)
691-
section_nr = i;
692-
section_count++;
693-
}
684+
i++)
685+
if (present_section_nr(i))
686+
section_count++;
694687

695688
if (section_count == 0)
696689
return 0;
697-
ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE);
690+
ret = init_memory_block(&mem, base_memory_block_id(base_section_nr),
691+
MEM_ONLINE);
698692
if (ret)
699693
return ret;
700694
mem->section_count = section_count;
@@ -707,6 +701,7 @@ static int add_memory_block(int base_section_nr)
707701
*/
708702
int hotplug_memory_register(int nid, struct mem_section *section)
709703
{
704+
int block_id = base_memory_block_id(__section_nr(section));
710705
int ret = 0;
711706
struct memory_block *mem;
712707

@@ -717,7 +712,7 @@ int hotplug_memory_register(int nid, struct mem_section *section)
717712
mem->section_count++;
718713
put_device(&mem->dev);
719714
} else {
720-
ret = init_memory_block(&mem, section, MEM_OFFLINE);
715+
ret = init_memory_block(&mem, block_id, MEM_OFFLINE);
721716
if (ret)
722717
goto out;
723718
mem->section_count++;

0 commit comments

Comments
 (0)