* [PATCH] mtd: fixing memory leak and handling failed kmalloc
@ 2015-12-29 18:45 Insu Yun
2016-01-07 1:24 ` Brian Norris
0 siblings, 1 reply; 2+ messages in thread
From: Insu Yun @ 2015-12-29 18:45 UTC (permalink / raw)
To: dwmw2, computersforpeace, linux-mtd, linux-kernel
Cc: taesoo, yeongjin.jang, insu, changwoo, Insu Yun
kmalloc needs to be handled when failing in memory pressure.
Also, it has memory leak in error routine.
Signed-off-by: Insu Yun <wuninsu@gmail.com>
---
drivers/mtd/chips/cfi_cmdset_0001.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 286b97a..5e1b68c 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -596,7 +596,7 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
mtd->size = devsize * cfi->numchips;
mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
- mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info)
+ mtd->eraseregions = kzalloc(sizeof(struct mtd_erase_region_info)
* mtd->numeraseregions, GFP_KERNEL);
if (!mtd->eraseregions)
goto setup_err;
@@ -614,6 +614,8 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].erasesize = ersize;
mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].numblocks = ernum;
mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].lockmap = kmalloc(ernum / 8 + 1, GFP_KERNEL);
+ if (!mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].lockmap)
+ goto setup_err;
}
offset += (ersize * ernum);
}
@@ -650,6 +652,10 @@ static struct mtd_info *cfi_intelext_setup(struct mtd_info *mtd)
return mtd;
setup_err:
+ if (mtd->eraseregions)
+ for (i=0; i<cfi->cfiq->NumEraseRegions; i++)
+ for (j=0; j<cfi->numchips; j++)
+ kfree(mtd->eraseregions[(j*cfi->cfiq->NumEraseRegions)+i].lockmap);
kfree(mtd->eraseregions);
kfree(mtd);
kfree(cfi->cmdset_priv);
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: fixing memory leak and handling failed kmalloc
2015-12-29 18:45 [PATCH] mtd: fixing memory leak and handling failed kmalloc Insu Yun
@ 2016-01-07 1:24 ` Brian Norris
0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2016-01-07 1:24 UTC (permalink / raw)
To: Insu Yun
Cc: dwmw2, linux-mtd, linux-kernel, taesoo, yeongjin.jang, insu,
changwoo
On Tue, Dec 29, 2015 at 01:45:09PM -0500, Insu Yun wrote:
> kmalloc needs to be handled when failing in memory pressure.
> Also, it has memory leak in error routine.
>
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
Applied to l2-mtd.git
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-07 1:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-29 18:45 [PATCH] mtd: fixing memory leak and handling failed kmalloc Insu Yun
2016-01-07 1:24 ` 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).