@@ -816,21 +816,6 @@ static int add_memory_block(unsigned long block_id, unsigned long state,
816
816
return 0 ;
817
817
}
818
818
819
- static int __init add_boot_memory_block (unsigned long base_section_nr )
820
- {
821
- unsigned long nr ;
822
-
823
- for_each_present_section_nr (base_section_nr , nr ) {
824
- if (nr >= (base_section_nr + sections_per_block ))
825
- break ;
826
-
827
- return add_memory_block (memory_block_id (base_section_nr ),
828
- MEM_ONLINE , NULL , NULL );
829
- }
830
-
831
- return 0 ;
832
- }
833
-
834
819
static int add_hotplug_memory_block (unsigned long block_id ,
835
820
struct vmem_altmap * altmap ,
836
821
struct memory_group * group )
@@ -957,7 +942,7 @@ static const struct attribute_group *memory_root_attr_groups[] = {
957
942
void __init memory_dev_init (void )
958
943
{
959
944
int ret ;
960
- unsigned long block_sz , nr ;
945
+ unsigned long block_sz , block_id , nr ;
961
946
962
947
/* Validate the configured memory block size */
963
948
block_sz = memory_block_size_bytes ();
@@ -970,15 +955,23 @@ void __init memory_dev_init(void)
970
955
panic ("%s() failed to register subsystem: %d\n" , __func__ , ret );
971
956
972
957
/*
973
- * Create entries for memory sections that were found
974
- * during boot and have been initialized
958
+ * Create entries for memory sections that were found during boot
959
+ * and have been initialized. Use @block_id to track the last
960
+ * handled block and initialize it to an invalid value (ULONG_MAX)
961
+ * to bypass the block ID matching check for the first present
962
+ * block so that it can be covered.
975
963
*/
976
- for (nr = 0 ; nr <= __highest_present_section_nr ;
977
- nr += sections_per_block ) {
978
- ret = add_boot_memory_block (nr );
979
- if (ret )
980
- panic ("%s() failed to add memory block: %d\n" , __func__ ,
981
- ret );
964
+ block_id = ULONG_MAX ;
965
+ for_each_present_section_nr (0 , nr ) {
966
+ if (block_id != ULONG_MAX && memory_block_id (nr ) == block_id )
967
+ continue ;
968
+
969
+ block_id = memory_block_id (nr );
970
+ ret = add_memory_block (block_id , MEM_ONLINE , NULL , NULL );
971
+ if (ret ) {
972
+ panic ("%s() failed to add memory block: %d\n" ,
973
+ __func__ , ret );
974
+ }
982
975
}
983
976
}
984
977
0 commit comments