Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtd: jedec_probe: use struct_size() helper for cfiq allocation

Documentation/process/deprecated.rst recommends against performing
dynamic size calculations in the arguments of memory allocator
functions due to the risk of overflow. Such calculations can wrap
around and result in a smaller allocation than expected.

Replace the size calculation in cfiq allocation with struct_size()
helper to make the code clearer and handle overflows correctly.

Signed-off-by: Rahul Kumar <rk0006818@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

authored by

Rahul Kumar and committed by
Miquel Raynal
52766886 d496b6f4

+1 -1
+1 -1
drivers/mtd/chips/jedec_probe.c
··· 1985 1985 1986 1986 num_erase_regions = jedec_table[index].nr_regions; 1987 1987 1988 - cfi->cfiq = kmalloc(sizeof(struct cfi_ident) + num_erase_regions * 4, GFP_KERNEL); 1988 + cfi->cfiq = kmalloc(struct_size(cfi->cfiq, EraseRegionInfo, num_erase_regions), GFP_KERNEL); 1989 1989 if (!cfi->cfiq) { 1990 1990 //xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name); 1991 1991 return 0;