summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWenwen Wang <wenwen@cs.uga.edu>2019-08-18 18:36:44 +0200
committerRichard Weinberger <richard@nod.at>2019-09-15 23:50:50 +0200
commit137e92fd14959506269d58e08dae35c0bb745211 (patch)
treeb6582b3f91d2159b229ad34898f99ca30a8494fe
parentmtd: parsers: Move CMDLINE parser (diff)
downloadlinux-137e92fd14959506269d58e08dae35c0bb745211.tar.xz
linux-137e92fd14959506269d58e08dae35c0bb745211.zip
mtd: sm_ftl: Fix memory leak in sm_init_zone() error path
In sm_init_zone(), 'zone->lba_to_phys_table' is allocated through kmalloc_array() and 'zone->free_sectors' is allocated in kfifo_alloc() respectively. However, they are not deallocated in the following execution if sm_read_sector() fails, leading to memory leaks. To fix this issue, free them before returning -EIO. Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu> Signed-off-by: Richard Weinberger <richard@nod.at>
-rw-r--r--drivers/mtd/sm_ftl.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
index dfc47a444b90..4744bf94ad9a 100644
--- a/drivers/mtd/sm_ftl.c
+++ b/drivers/mtd/sm_ftl.c
@@ -774,8 +774,11 @@ static int sm_init_zone(struct sm_ftl *ftl, int zone_num)
continue;
/* Read the oob of first sector */
- if (sm_read_sector(ftl, zone_num, block, 0, NULL, &oob))
+ if (sm_read_sector(ftl, zone_num, block, 0, NULL, &oob)) {
+ kfifo_free(&zone->free_sectors);
+ kfree(zone->lba_to_phys_table);
return -EIO;
+ }
/* Test to see if block is erased. It is enough to test
first sector, because erase happens in one shot */