@@ -588,30 +588,13 @@ int __weak arch_get_memory_phys_device(unsigned long start_pfn)
588588 return 0 ;
589589}
590590
591- /*
592- * A reference for the returned object is held and the reference for the
593- * hinted object is released.
594- */
595- static struct memory_block * find_memory_block_by_id (unsigned long block_id ,
596- struct memory_block * hint )
591+ /* A reference for the returned memory block device is acquired. */
592+ static struct memory_block * find_memory_block_by_id (unsigned long block_id )
597593{
598- struct device * hintdev = hint ? & hint -> dev : NULL ;
599594 struct device * dev ;
600595
601- dev = subsys_find_device_by_id (& memory_subsys , block_id , hintdev );
602- if (hint )
603- put_device (& hint -> dev );
604- if (!dev )
605- return NULL ;
606- return to_memory_block (dev );
607- }
608-
609- struct memory_block * find_memory_block_hinted (struct mem_section * section ,
610- struct memory_block * hint )
611- {
612- unsigned long block_id = base_memory_block_id (__section_nr (section ));
613-
614- return find_memory_block_by_id (block_id , hint );
596+ dev = subsys_find_device_by_id (& memory_subsys , block_id , NULL );
597+ return dev ? to_memory_block (dev ) : NULL ;
615598}
616599
617600/*
@@ -624,7 +607,9 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
624607 */
625608struct memory_block * find_memory_block (struct mem_section * section )
626609{
627- return find_memory_block_hinted (section , NULL );
610+ unsigned long block_id = base_memory_block_id (__section_nr (section ));
611+
612+ return find_memory_block_by_id (block_id );
628613}
629614
630615static struct attribute * memory_memblk_attrs [] = {
@@ -675,7 +660,7 @@ static int init_memory_block(struct memory_block **memory,
675660 unsigned long start_pfn ;
676661 int ret = 0 ;
677662
678- mem = find_memory_block_by_id (block_id , NULL );
663+ mem = find_memory_block_by_id (block_id );
679664 if (mem ) {
680665 put_device (& mem -> dev );
681666 return - EEXIST ;
@@ -755,7 +740,7 @@ int create_memory_block_devices(unsigned long start, unsigned long size)
755740 end_block_id = block_id ;
756741 for (block_id = start_block_id ; block_id != end_block_id ;
757742 block_id ++ ) {
758- mem = find_memory_block_by_id (block_id , NULL );
743+ mem = find_memory_block_by_id (block_id );
759744 mem -> section_count = 0 ;
760745 unregister_memory (mem );
761746 }
@@ -782,7 +767,7 @@ void remove_memory_block_devices(unsigned long start, unsigned long size)
782767
783768 mutex_lock (& mem_sysfs_mutex );
784769 for (block_id = start_block_id ; block_id != end_block_id ; block_id ++ ) {
785- mem = find_memory_block_by_id (block_id , NULL );
770+ mem = find_memory_block_by_id (block_id );
786771 if (WARN_ON_ONCE (!mem ))
787772 continue ;
788773 mem -> section_count = 0 ;
@@ -881,8 +866,11 @@ int walk_memory_blocks(unsigned long start, unsigned long size,
881866 unsigned long block_id ;
882867 int ret = 0 ;
883868
869+ if (!size )
870+ return 0 ;
871+
884872 for (block_id = start_block_id ; block_id <= end_block_id ; block_id ++ ) {
885- mem = find_memory_block_by_id (block_id , NULL );
873+ mem = find_memory_block_by_id (block_id );
886874 if (!mem )
887875 continue ;
888876
0 commit comments