Skip to content

Commit 5276688

Browse files
rahul19kumar8miquelraynal
authored andcommitted
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>
1 parent d496b6f commit 5276688

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/mtd/chips/jedec_probe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ static int cfi_jedec_setup(struct map_info *map, struct cfi_private *cfi, int in
19851985

19861986
num_erase_regions = jedec_table[index].nr_regions;
19871987

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);
19891989
if (!cfi->cfiq) {
19901990
//xx printk(KERN_WARNING "%s: kmalloc failed for CFI ident structure\n", map->name);
19911991
return 0;

0 commit comments

Comments
 (0)