Skip to content

Commit 79ad07d

Browse files
Dan Carpentercomputersforpeace
authored andcommitted
mtd: pmcmsp-flash: Allocating too much in init_msp_flash()
There is a cut and paste issue here. The bug is that we are allocating more memory than necessary for msp_maps. We should be allocating enough space for a map_info struct (144 bytes) but we instead allocate enough for an mtd_info struct (1840 bytes). It's a small waste. The other part of this is not harmful but when we allocated msp_flash then we allocated enough space fro a map_info pointer instead of an mtd_info pointer. But since pointers are the same size it works out fine. Anyway, I decided to clean up all three allocations a bit to make them a bit more consistent and clear. Fixes: 68aa0fa ('[MTD] PMC MSP71xx flash/rootfs mappings') Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Brian Norris <[email protected]>
1 parent dc01a28 commit 79ad07d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/mtd/maps/pmcmsp-flash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ static int __init init_msp_flash(void)
7575

7676
printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt);
7777

78-
msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
78+
msp_flash = kcalloc(fcnt, sizeof(*msp_flash), GFP_KERNEL);
7979
if (!msp_flash)
8080
return -ENOMEM;
8181

82-
msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
82+
msp_parts = kcalloc(fcnt, sizeof(*msp_parts), GFP_KERNEL);
8383
if (!msp_parts)
8484
goto free_msp_flash;
8585

86-
msp_maps = kcalloc(fcnt, sizeof(struct mtd_info), GFP_KERNEL);
86+
msp_maps = kcalloc(fcnt, sizeof(*msp_maps), GFP_KERNEL);
8787
if (!msp_maps)
8888
goto free_msp_parts;
8989

0 commit comments

Comments
 (0)