@@ -759,32 +759,31 @@ int create_memory_block_devices(unsigned long start, unsigned long size)
759759 return ret ;
760760}
761761
762- void unregister_memory_section (struct mem_section * section )
762+ /*
763+ * Remove memory block devices for the given memory area. Start and size
764+ * have to be aligned to memory block granularity. Memory block devices
765+ * have to be offline.
766+ */
767+ void remove_memory_block_devices (unsigned long start , unsigned long size )
763768{
769+ const int start_block_id = pfn_to_block_id (PFN_DOWN (start ));
770+ const int end_block_id = pfn_to_block_id (PFN_DOWN (start + size ));
764771 struct memory_block * mem ;
772+ int block_id ;
765773
766- if (WARN_ON_ONCE (!present_section (section )))
774+ if (WARN_ON_ONCE (!IS_ALIGNED (start , memory_block_size_bytes ()) ||
775+ !IS_ALIGNED (size , memory_block_size_bytes ())))
767776 return ;
768777
769778 mutex_lock (& mem_sysfs_mutex );
770-
771- /*
772- * Some users of the memory hotplug do not want/need memblock to
773- * track all sections. Skip over those.
774- */
775- mem = find_memory_block (section );
776- if (!mem )
777- goto out_unlock ;
778-
779- unregister_mem_sect_under_nodes (mem , __section_nr (section ));
780-
781- mem -> section_count -- ;
782- if (mem -> section_count == 0 )
779+ for (block_id = start_block_id ; block_id != end_block_id ; block_id ++ ) {
780+ mem = find_memory_block_by_id (block_id , NULL );
781+ if (WARN_ON_ONCE (!mem ))
782+ continue ;
783+ mem -> section_count = 0 ;
784+ unregister_memory_block_under_nodes (mem );
783785 unregister_memory (mem );
784- else
785- put_device (& mem -> dev );
786-
787- out_unlock :
786+ }
788787 mutex_unlock (& mem_sysfs_mutex );
789788}
790789
0 commit comments