Commit bbd06825 authored by WANG Cong's avatar WANG Cong Committed by Linus Torvalds

mm/sparse.c: improve the error handling for sparse_add_one_section()

Improve the error handling for mm/sparse.c::sparse_add_one_section().  And I
see no reason to check 'usemap' until holding the 'pgdat_resize_lock'.

[geoffrey.levand@am.sony.com: sparse_index_init() returns -EEXIST]
Cc: Christoph Lameter <clameter@sgi.com>
Acked-by: default avatarDave Hansen <haveblue@us.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Acked-by: default avatarYasunori Goto <y-goto@jp.fujitsu.com>
Cc: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: default avatarWANG Cong <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarGeoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent af0cd5a7
...@@ -391,9 +391,17 @@ int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, ...@@ -391,9 +391,17 @@ int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
* no locking for this, because it does its own * no locking for this, because it does its own
* plus, it does a kmalloc * plus, it does a kmalloc
*/ */
sparse_index_init(section_nr, pgdat->node_id); ret = sparse_index_init(section_nr, pgdat->node_id);
if (ret < 0 && ret != -EEXIST)
return ret;
memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages); memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages);
if (!memmap)
return -ENOMEM;
usemap = __kmalloc_section_usemap(); usemap = __kmalloc_section_usemap();
if (!usemap) {
__kfree_section_memmap(memmap, nr_pages);
return -ENOMEM;
}
pgdat_resize_lock(pgdat, &flags); pgdat_resize_lock(pgdat, &flags);
...@@ -403,18 +411,16 @@ int sparse_add_one_section(struct zone *zone, unsigned long start_pfn, ...@@ -403,18 +411,16 @@ int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
goto out; goto out;
} }
if (!usemap) {
ret = -ENOMEM;
goto out;
}
ms->section_mem_map |= SECTION_MARKED_PRESENT; ms->section_mem_map |= SECTION_MARKED_PRESENT;
ret = sparse_init_one_section(ms, section_nr, memmap, usemap); ret = sparse_init_one_section(ms, section_nr, memmap, usemap);
out: out:
pgdat_resize_unlock(pgdat, &flags); pgdat_resize_unlock(pgdat, &flags);
if (ret <= 0) if (ret <= 0) {
kfree(usemap);
__kfree_section_memmap(memmap, nr_pages); __kfree_section_memmap(memmap, nr_pages);
}
return ret; return ret;
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment