Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Gavin Shan and committed by
Andrew Morton
61659efd c637c61c

+13 -14
+8 -9
drivers/base/memory.c
··· 818 818 819 819 static int __init add_boot_memory_block(unsigned long base_section_nr) 820 820 { 821 - int section_count = 0; 822 821 unsigned long nr; 823 822 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; 828 826 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; 833 832 } 834 833 835 834 static int add_hotplug_memory_block(unsigned long block_id,
+5
include/linux/mmzone.h
··· 2140 2140 return -1; 2141 2141 } 2142 2142 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 + 2143 2148 /* 2144 2149 * These are _only_ used during initialisation, therefore they 2145 2150 * can use __initdata ... They could have names to indicate
-5
mm/sparse.c
··· 170 170 ms->section_mem_map |= SECTION_MARKED_PRESENT; 171 171 } 172 172 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 - 178 173 static inline unsigned long first_present_section_nr(void) 179 174 { 180 175 return next_present_section_nr(-1);