Skip to content

Commit bf508ec

Browse files
GustavoARSilvawilldeacon
authored andcommitted
arm64: kexec_file: Use struct_size() in kmalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://lore.kernel.org/r/20200617213407.GA1385@embeddedor Signed-off-by: Will Deacon <will@kernel.org>
1 parent 618e078 commit bf508ec

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

‎arch/arm64/kernel/machine_kexec_file.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ static int prepare_elf_headers(void **addr, unsigned long *sz)
219219
MEMBLOCK_NONE, &start, &end, NULL)
220220
nr_ranges++;
221221

222-
cmem = kmalloc(sizeof(struct crash_mem) +
223-
sizeof(struct crash_mem_range) * nr_ranges, GFP_KERNEL);
222+
cmem = kmalloc(struct_size(cmem, ranges, nr_ranges), GFP_KERNEL);
224223
if (!cmem)
225224
return -ENOMEM;
226225

0 commit comments

Comments
 (0)