mtd: phram: fix memory leak

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Fri Mar 11 10:59:03 EST 2011


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=f17f12ce9dd6ec0a8e1f415ecdbaebfce0207464
Commit:     f17f12ce9dd6ec0a8e1f415ecdbaebfce0207464
Parent:     07be303d22ac7e067b8a7172a4043ebe32b74b33
Author:     Mathias Krause <minipli at googlemail.com>
AuthorDate: Sun Jan 30 10:31:48 2011 +0100
Committer:  David Woodhouse <David.Woodhouse at intel.com>
CommitDate: Fri Mar 11 14:22:43 2011 +0000

    mtd: phram: fix memory leak
    
    Commit 4f678a58 (mtd: fix memory leaks in phram_setup) missed two cases
    where the memory allocated for name would be leaked. This commit frees
    the memory when register_device() fails and on unregister_devices().
    
    Signed-off-by: Mathias Krause <minipli at googlemail.com>
    Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
    Signed-off-by: David Woodhouse <David.Woodhouse at intel.com>
---
 drivers/mtd/devices/phram.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 5239328..8d28fa0 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -117,6 +117,7 @@ static void unregister_devices(void)
 	list_for_each_entry_safe(this, safe, &phram_list, list) {
 		del_mtd_device(&this->mtd);
 		iounmap(this->mtd.priv);
+		kfree(this->mtd.name);
 		kfree(this);
 	}
 }
@@ -275,6 +276,8 @@ static int phram_setup(const char *val, struct kernel_param *kp)
 	ret = register_device(name, start, len);
 	if (!ret)
 		pr_info("%s device: %#x at %#x\n", name, len, start);
+	else
+		kfree(name);
 
 	return ret;
 }



More information about the linux-mtd-cvs mailing list