Add a flag to init_memory_block() to enable/disable searching for a
matching block before creating a device for the block and adding it to
the memory subsystem's bus.
When the memory subsystem is being initialized there is no need to check
if a given block has already been added to its bus. The bus is new, so the
block in question cannot yet have a corresponding device.
The search for a missing block is O(n) so this saves substantial time at
boot if there are many such blocks to add.
Signed-off-by: Scott Cheloha <cheloha@xxxxxxxxxxxxxxxxxx>
---
drivers/base/memory.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 55907c27075b..1160df4a8feb 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -643,17 +643,21 @@ int register_memory(struct memory_block *memory)
}
static int init_memory_block(struct memory_block **memory,
- unsigned long block_id, unsigned long state)
+ unsigned long block_id, unsigned long state,
+ bool may_exist)
{
struct memory_block *mem;
unsigned long start_pfn;
int ret = 0;
- mem = find_memory_block_by_id(block_id);
- if (mem) {
- put_device(&mem->dev);
- return -EEXIST;
+ if (may_exist) {
+ mem = find_memory_block_by_id(block_id);
+ if (mem) {
+ put_device(&mem->dev);
+ return -EEXIST;
+ }