linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] mtd: pmcmsp-flash: Allocating too much in init_msp_flash()
@ 2016-07-14 10:44 Dan Carpenter
  2016-07-16  5:45 ` Brian Norris
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-07-14 10:44 UTC (permalink / raw)
  To: David Woodhouse, Marc St-Jean
  Cc: Brian Norris, linux-mtd, linux-kernel, kernel-janitors

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>
---
Not tested!!

diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index 744ca5c..f9fa3fa 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)
 
 	printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt);
 
-	msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL);
+	msp_flash = kcalloc(fcnt, sizeof(*msp_flash), GFP_KERNEL);
 	if (!msp_flash)
 		return -ENOMEM;
 
-	msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL);
+	msp_parts = kcalloc(fcnt, sizeof(*msp_parts), GFP_KERNEL);
 	if (!msp_parts)
 		goto free_msp_flash;
 
-	msp_maps = kcalloc(fcnt, sizeof(struct mtd_info), GFP_KERNEL);
+	msp_maps = kcalloc(fcnt, sizeof(*msp_maps), GFP_KERNEL);
 	if (!msp_maps)
 		goto free_msp_parts;
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] mtd: pmcmsp-flash: Allocating too much in init_msp_flash()
  2016-07-14 10:44 [patch] mtd: pmcmsp-flash: Allocating too much in init_msp_flash() Dan Carpenter
@ 2016-07-16  5:45 ` Brian Norris
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2016-07-16  5:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: David Woodhouse, Marc St-Jean, linux-mtd, linux-kernel, kernel-janitors

On Thu, Jul 14, 2016 at 01:44:56PM +0300, Dan Carpenter wrote:
> 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>

Applied to l2-mtd.git.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-16  5:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14 10:44 [patch] mtd: pmcmsp-flash: Allocating too much in init_msp_flash() Dan Carpenter
2016-07-16  5:45 ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).