mtd: mtdblock: test return value of add_mtd_blktrans_dev, because if can fail

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Feb 26 13:59:02 EST 2010


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=298304f1a554d44cf13391e531ced3cde69a8ce4
Commit:     298304f1a554d44cf13391e531ced3cde69a8ce4
Parent:     048d87199566663e4edc4880df3703c04bcf41d9
Author:     Maxim Levitsky <maximlevitsky at gmail.com>
AuthorDate: Mon Feb 22 20:39:31 2010 +0200
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Fri Feb 26 17:05:46 2010 +0000

    mtd: mtdblock: test return value of add_mtd_blktrans_dev, because if can fail
    
    This prevents a memory leak
    
    Signed-off-by: Maxim Levitsky <maximlevitsky at gmail.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/mtdblock.c    |    3 ++-
 drivers/mtd/mtdblock_ro.c |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 8e5da1e..7ce30a2 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -348,7 +348,8 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	if (!(mtd->flags & MTD_WRITEABLE))
 		dev->mbd.readonly = 1;
 
-	add_mtd_blktrans_dev(&dev->mbd);
+	if (add_mtd_blktrans_dev(&dev->mbd))
+		kfree(dev);
 }
 
 static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 54ff288..d0d3f79 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -43,7 +43,8 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
 	dev->tr = tr;
 	dev->readonly = 1;
 
-	add_mtd_blktrans_dev(dev);
+	if (add_mtd_blktrans_dev(dev))
+		kfree(dev);
 }
 
 static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)



More information about the linux-mtd-cvs mailing list