Skip to content

Commit 23a7052

Browse files
rppttorvalds
authored andcommitted
mm/page_alloc.c: check return value of memblock_alloc_node_nopanic()
There are two early memory allocations that use memblock_alloc_node_nopanic() and do not check its return value. While this happens very early during boot and chances that the allocation will fail are diminishing, it is still worth to have proper checks for the allocation errors. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport <[email protected]> Reviewed-by: William Kucharski <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8ef5cbd commit 23a7052

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mm/page_alloc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6431,10 +6431,14 @@ static void __ref setup_usemap(struct pglist_data *pgdat,
64316431
{
64326432
unsigned long usemapsize = usemap_size(zone_start_pfn, zonesize);
64336433
zone->pageblock_flags = NULL;
6434-
if (usemapsize)
6434+
if (usemapsize) {
64356435
zone->pageblock_flags =
64366436
memblock_alloc_node_nopanic(usemapsize,
64376437
pgdat->node_id);
6438+
if (!zone->pageblock_flags)
6439+
panic("Failed to allocate %ld bytes for zone %s pageblock flags on node %d\n",
6440+
usemapsize, zone->name, pgdat->node_id);
6441+
}
64386442
}
64396443
#else
64406444
static inline void setup_usemap(struct pglist_data *pgdat, struct zone *zone,
@@ -6664,6 +6668,9 @@ static void __ref alloc_node_mem_map(struct pglist_data *pgdat)
66646668
end = ALIGN(end, MAX_ORDER_NR_PAGES);
66656669
size = (end - start) * sizeof(struct page);
66666670
map = memblock_alloc_node_nopanic(size, pgdat->node_id);
6671+
if (!map)
6672+
panic("Failed to allocate %ld bytes for node %d memory map\n",
6673+
size, pgdat->node_id);
66676674
pgdat->node_mem_map = map + offset;
66686675
}
66696676
pr_debug("%s: node %d, pgdat %08lx, node_mem_map %08lx\n",

0 commit comments

Comments
 (0)