@@ -1086,6 +1086,7 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
1086
1086
struct pcpu_chunk * chunk ;
1087
1087
unsigned long aligned_addr , lcm_align ;
1088
1088
int start_offset , offset_bits , region_size , region_bits ;
1089
+ size_t alloc_size ;
1089
1090
1090
1091
/* region calculations */
1091
1092
aligned_addr = tmp_addr & PAGE_MASK ;
@@ -1101,9 +1102,12 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
1101
1102
region_size = ALIGN (start_offset + map_size , lcm_align );
1102
1103
1103
1104
/* allocate chunk */
1104
- chunk = memblock_alloc (sizeof (struct pcpu_chunk ) +
1105
- BITS_TO_LONGS (region_size >> PAGE_SHIFT ),
1106
- SMP_CACHE_BYTES );
1105
+ alloc_size = sizeof (struct pcpu_chunk ) +
1106
+ BITS_TO_LONGS (region_size >> PAGE_SHIFT );
1107
+ chunk = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
1108
+ if (!chunk )
1109
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
1110
+ alloc_size );
1107
1111
1108
1112
INIT_LIST_HEAD (& chunk -> list );
1109
1113
@@ -1114,12 +1118,25 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
1114
1118
chunk -> nr_pages = region_size >> PAGE_SHIFT ;
1115
1119
region_bits = pcpu_chunk_map_bits (chunk );
1116
1120
1117
- chunk -> alloc_map = memblock_alloc (BITS_TO_LONGS (region_bits ) * sizeof (chunk -> alloc_map [0 ]),
1118
- SMP_CACHE_BYTES );
1119
- chunk -> bound_map = memblock_alloc (BITS_TO_LONGS (region_bits + 1 ) * sizeof (chunk -> bound_map [0 ]),
1120
- SMP_CACHE_BYTES );
1121
- chunk -> md_blocks = memblock_alloc (pcpu_chunk_nr_blocks (chunk ) * sizeof (chunk -> md_blocks [0 ]),
1122
- SMP_CACHE_BYTES );
1121
+ alloc_size = BITS_TO_LONGS (region_bits ) * sizeof (chunk -> alloc_map [0 ]);
1122
+ chunk -> alloc_map = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
1123
+ if (!chunk -> alloc_map )
1124
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
1125
+ alloc_size );
1126
+
1127
+ alloc_size =
1128
+ BITS_TO_LONGS (region_bits + 1 ) * sizeof (chunk -> bound_map [0 ]);
1129
+ chunk -> bound_map = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
1130
+ if (!chunk -> bound_map )
1131
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
1132
+ alloc_size );
1133
+
1134
+ alloc_size = pcpu_chunk_nr_blocks (chunk ) * sizeof (chunk -> md_blocks [0 ]);
1135
+ chunk -> md_blocks = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
1136
+ if (!chunk -> md_blocks )
1137
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
1138
+ alloc_size );
1139
+
1123
1140
pcpu_init_md_blocks (chunk );
1124
1141
1125
1142
/* manage populated page bitmap */
@@ -2044,6 +2061,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
2044
2061
int group , unit , i ;
2045
2062
int map_size ;
2046
2063
unsigned long tmp_addr ;
2064
+ size_t alloc_size ;
2047
2065
2048
2066
#define PCPU_SETUP_BUG_ON (cond ) do { \
2049
2067
if (unlikely(cond)) { \
@@ -2075,14 +2093,29 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
2075
2093
PCPU_SETUP_BUG_ON (pcpu_verify_alloc_info (ai ) < 0 );
2076
2094
2077
2095
/* process group information and build config tables accordingly */
2078
- group_offsets = memblock_alloc (ai -> nr_groups * sizeof (group_offsets [0 ]),
2079
- SMP_CACHE_BYTES );
2080
- group_sizes = memblock_alloc (ai -> nr_groups * sizeof (group_sizes [0 ]),
2081
- SMP_CACHE_BYTES );
2082
- unit_map = memblock_alloc (nr_cpu_ids * sizeof (unit_map [0 ]),
2083
- SMP_CACHE_BYTES );
2084
- unit_off = memblock_alloc (nr_cpu_ids * sizeof (unit_off [0 ]),
2085
- SMP_CACHE_BYTES );
2096
+ alloc_size = ai -> nr_groups * sizeof (group_offsets [0 ]);
2097
+ group_offsets = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
2098
+ if (!group_offsets )
2099
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
2100
+ alloc_size );
2101
+
2102
+ alloc_size = ai -> nr_groups * sizeof (group_sizes [0 ]);
2103
+ group_sizes = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
2104
+ if (!group_sizes )
2105
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
2106
+ alloc_size );
2107
+
2108
+ alloc_size = nr_cpu_ids * sizeof (unit_map [0 ]);
2109
+ unit_map = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
2110
+ if (!unit_map )
2111
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
2112
+ alloc_size );
2113
+
2114
+ alloc_size = nr_cpu_ids * sizeof (unit_off [0 ]);
2115
+ unit_off = memblock_alloc (alloc_size , SMP_CACHE_BYTES );
2116
+ if (!unit_off )
2117
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
2118
+ alloc_size );
2086
2119
2087
2120
for (cpu = 0 ; cpu < nr_cpu_ids ; cpu ++ )
2088
2121
unit_map [cpu ] = UINT_MAX ;
@@ -2148,6 +2181,9 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
2148
2181
pcpu_nr_slots = __pcpu_size_to_slot (pcpu_unit_size ) + 2 ;
2149
2182
pcpu_slot = memblock_alloc (pcpu_nr_slots * sizeof (pcpu_slot [0 ]),
2150
2183
SMP_CACHE_BYTES );
2184
+ if (!pcpu_slot )
2185
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
2186
+ pcpu_nr_slots * sizeof (pcpu_slot [0 ]));
2151
2187
for (i = 0 ; i < pcpu_nr_slots ; i ++ )
2152
2188
INIT_LIST_HEAD (& pcpu_slot [i ]);
2153
2189
@@ -2602,6 +2638,9 @@ int __init pcpu_page_first_chunk(size_t reserved_size,
2602
2638
pages_size = PFN_ALIGN (unit_pages * num_possible_cpus () *
2603
2639
sizeof (pages [0 ]));
2604
2640
pages = memblock_alloc (pages_size , SMP_CACHE_BYTES );
2641
+ if (!pages )
2642
+ panic ("%s: Failed to allocate %zu bytes\n" , __func__ ,
2643
+ pages_size );
2605
2644
2606
2645
/* allocate pages */
2607
2646
j = 0 ;
0 commit comments