diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2016-07-14 06:44:56 -0400 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2016-07-16 00:52:34 -0400 |
commit | 79ad07d45743721010e766e65dc004ad249bd429 (patch) | |
tree | fa08ef2c8fbdc046b0c32ea229ffbfb38839d12f | |
parent | dc01a28d80a42cef08c94dfc595565aaebe46d15 (diff) |
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: 68aa0fa87f6d ('[MTD] PMC MSP71xx flash/rootfs mappings')
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r-- | drivers/mtd/maps/pmcmsp-flash.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c index 744ca5cacc9b..f9fa3fad728e 100644 --- a/drivers/mtd/maps/pmcmsp-flash.c +++ b/drivers/mtd/maps/pmcmsp-flash.c | |||
@@ -75,15 +75,15 @@ static int __init init_msp_flash(void) | |||
75 | 75 | ||
76 | printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt); | 76 | printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt); |
77 | 77 | ||
78 | msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL); | 78 | msp_flash = kcalloc(fcnt, sizeof(*msp_flash), GFP_KERNEL); |
79 | if (!msp_flash) | 79 | if (!msp_flash) |
80 | return -ENOMEM; | 80 | return -ENOMEM; |
81 | 81 | ||
82 | msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL); | 82 | msp_parts = kcalloc(fcnt, sizeof(*msp_parts), GFP_KERNEL); |
83 | if (!msp_parts) | 83 | if (!msp_parts) |
84 | goto free_msp_flash; | 84 | goto free_msp_flash; |
85 | 85 | ||
86 | msp_maps = kcalloc(fcnt, sizeof(struct mtd_info), GFP_KERNEL); | 86 | msp_maps = kcalloc(fcnt, sizeof(*msp_maps), GFP_KERNEL); |
87 | if (!msp_maps) | 87 | if (!msp_maps) |
88 | goto free_msp_parts; | 88 | goto free_msp_parts; |
89 | 89 | ||