Skip to content

Commit 61cf93d

Browse files
committed
percpu: convert flexible array initializers to use struct_size()
Use the safer macro as sparked by the long discussion in [1]. [1] https://lore.kernel.org/lkml/20200917204514.GA2880159@google.com/ Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Dennis Zhou <dennis@kernel.org>
1 parent 29813a2 commit 61cf93d

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

mm/percpu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,8 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
13151315
region_size = ALIGN(start_offset + map_size, lcm_align);
13161316

13171317
/* allocate chunk */
1318-
alloc_size = sizeof(struct pcpu_chunk) +
1319-
BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(unsigned long);
1318+
alloc_size = struct_size(chunk, populated,
1319+
BITS_TO_LONGS(region_size >> PAGE_SHIFT));
13201320
chunk = memblock_alloc(alloc_size, SMP_CACHE_BYTES);
13211321
if (!chunk)
13221322
panic("%s: Failed to allocate %zu bytes\n", __func__,
@@ -2521,8 +2521,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
25212521
pcpu_unit_pages = ai->unit_size >> PAGE_SHIFT;
25222522
pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT;
25232523
pcpu_atom_size = ai->atom_size;
2524-
pcpu_chunk_struct_size = sizeof(struct pcpu_chunk) +
2525-
BITS_TO_LONGS(pcpu_unit_pages) * sizeof(unsigned long);
2524+
pcpu_chunk_struct_size = struct_size(chunk, populated,
2525+
BITS_TO_LONGS(pcpu_unit_pages));
25262526

25272527
pcpu_stats_save_ai(ai);
25282528

0 commit comments

Comments
 (0)