Skip to content

Commit 61659ef

Browse files
Gavin Shanakpm00
Gavin Shan
authored andcommitted
drivers/base/memory: improve add_boot_memory_block()
Patch series "drivers/base/memory: Two cleanups", v3. Two cleanups to drivers/base/memory. This patch (of 2)L It's unnecessary to count the present sections for the specified block since the block will be added if any section in the block is present. Besides, for_each_present_section_nr() can be reused as Andrew Morton suggested. Improve by using for_each_present_section_nr() and dropping the unnecessary @section_count. No functional changes intended. Link: https://lkml.kernel.org/r/20250311233045.148943-1-gshan@redhat.com Link: https://lkml.kernel.org/r/20250311233045.148943-2-gshan@redhat.com Signed-off-by: Gavin Shan <gshan@redhat.com> Acked-by: David Hildenbrand <david@redhat.com> Acked-by: Oscar Salvador <osalvador@suse.de> Cc: Danilo Krummrich <dakr@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: "Rafael J. Wysocki" <rafael@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent c637c61 commit 61659ef

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

drivers/base/memory.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -818,18 +818,17 @@ static int add_memory_block(unsigned long block_id, unsigned long state,
818818

819819
static int __init add_boot_memory_block(unsigned long base_section_nr)
820820
{
821-
int section_count = 0;
822821
unsigned long nr;
823822

824-
for (nr = base_section_nr; nr < base_section_nr + sections_per_block;
825-
nr++)
826-
if (present_section_nr(nr))
827-
section_count++;
823+
for_each_present_section_nr(base_section_nr, nr) {
824+
if (nr >= (base_section_nr + sections_per_block))
825+
break;
828826

829-
if (section_count == 0)
830-
return 0;
831-
return add_memory_block(memory_block_id(base_section_nr),
832-
MEM_ONLINE, NULL, NULL);
827+
return add_memory_block(memory_block_id(base_section_nr),
828+
MEM_ONLINE, NULL, NULL);
829+
}
830+
831+
return 0;
833832
}
834833

835834
static int add_hotplug_memory_block(unsigned long block_id,

include/linux/mmzone.h

+5
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,11 @@ static inline unsigned long next_present_section_nr(unsigned long section_nr)
21402140
return -1;
21412141
}
21422142

2143+
#define for_each_present_section_nr(start, section_nr) \
2144+
for (section_nr = next_present_section_nr(start - 1); \
2145+
section_nr != -1; \
2146+
section_nr = next_present_section_nr(section_nr))
2147+
21432148
/*
21442149
* These are _only_ used during initialisation, therefore they
21452150
* can use __initdata ... They could have names to indicate

mm/sparse.c

-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ static void __section_mark_present(struct mem_section *ms,
170170
ms->section_mem_map |= SECTION_MARKED_PRESENT;
171171
}
172172

173-
#define for_each_present_section_nr(start, section_nr) \
174-
for (section_nr = next_present_section_nr(start-1); \
175-
section_nr != -1; \
176-
section_nr = next_present_section_nr(section_nr))
177-
178173
static inline unsigned long first_present_section_nr(void)
179174
{
180175
return next_present_section_nr(-1);

0 commit comments

Comments
 (0)