mtd: mtdblock: test return value of add_mtd_blktrans_dev, because if can fail
authorMaxim Levitsky <maximlevitsky@gmail.com>
Mon, 22 Feb 2010 18:39:31 +0000 (20:39 +0200)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Fri, 26 Feb 2010 17:05:46 +0000 (17:05 +0000)
This prevents a memory leak

Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
drivers/mtd/mtdblock.c
drivers/mtd/mtdblock_ro.c

index 8e5da1e460766ea501496b151d35ad7ed8777749..7ce30a239ada05cf339106c58a78a569bd799cf4 100644 (file)
@@ -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)
index 54ff2880cf6591d6d71123f405c6823df319b142..d0d3f79f9d03e7a94a38f8c6d8f2f96530876c99 100644 (file)
@@ -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)