Skip to content

Commit d496b6f

Browse files
gopi487krishnamiquelraynal
authored andcommitted
mtd: cfi: use struct_size() helper for cfiq allocation
Documentation/process/deprecated.rst recommends against performing dynamic size calculations in the arguments of memory allocator function due to the risk of overflow. Such calculations can wrap around and result in a smaller allocation than what the caller was expecting. Replace the size calculation in cfiq allocation with struct_size() helper to make the code clearer and handle the overflows correctly. Signed-off-by: Gopi Krishna Menon <krishnagopi487@gmail.com> Reviewed-by: Vignesh Raghavendra <vigneshr@ti.com> link: https://lore.kernel.org/linux-kernel-mentees/20250922071137.900508-1-rk0006818@gmail.com/T/#u Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 9781c38 commit d496b6f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/mtd/chips/cfi_probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int __xipram cfi_chip_setup(struct map_info *map,
208208
if (!num_erase_regions)
209209
return 0;
210210

211-
cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL);
211+
cfi->cfiq = kmalloc(struct_size(cfi->cfiq, EraseRegionInfo, num_erase_regions), GFP_KERNEL);
212212
if (!cfi->cfiq)
213213
return 0;
214214

0 commit comments

Comments
 (0)