aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mm/sparse.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/mm/sparse.c b/mm/sparse.c
index d245e59048a8..a2183cb5d524 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -391,9 +391,17 @@ int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
391 * no locking for this, because it does its own 391 * no locking for this, because it does its own
392 * plus, it does a kmalloc 392 * plus, it does a kmalloc
393 */ 393 */
394 sparse_index_init(section_nr, pgdat->node_id); 394 ret = sparse_index_init(section_nr, pgdat->node_id);
395 if (ret < 0 && ret != -EEXIST)
396 return ret;
395 memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages); 397 memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages);
398 if (!memmap)
399 return -ENOMEM;
396 usemap = __kmalloc_section_usemap(); 400 usemap = __kmalloc_section_usemap();
401 if (!usemap) {
402 __kfree_section_memmap(memmap, nr_pages);
403 return -ENOMEM;
404 }
397 405
398 pgdat_resize_lock(pgdat, &flags); 406 pgdat_resize_lock(pgdat, &flags);
399 407
@@ -403,18 +411,16 @@ int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
403 goto out; 411 goto out;
404 } 412 }
405 413
406 if (!usemap) {
407 ret = -ENOMEM;
408 goto out;
409 }
410 ms->section_mem_map |= SECTION_MARKED_PRESENT; 414 ms->section_mem_map |= SECTION_MARKED_PRESENT;
411 415
412 ret = sparse_init_one_section(ms, section_nr, memmap, usemap); 416 ret = sparse_init_one_section(ms, section_nr, memmap, usemap);
413 417
414out: 418out:
415 pgdat_resize_unlock(pgdat, &flags); 419 pgdat_resize_unlock(pgdat, &flags);
416 if (ret <= 0) 420 if (ret <= 0) {
421 kfree(usemap);
417 __kfree_section_memmap(memmap, nr_pages); 422 __kfree_section_memmap(memmap, nr_pages);
423 }
418 return ret; 424 return ret;
419} 425}
420#endif 426#endif