Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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@googlemail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>

authored by

Mathias Krause and committed by
David Woodhouse
f17f12ce 07be303d

+3
+3
drivers/mtd/devices/phram.c
··· 117 117 list_for_each_entry_safe(this, safe, &phram_list, list) { 118 118 del_mtd_device(&this->mtd); 119 119 iounmap(this->mtd.priv); 120 + kfree(this->mtd.name); 120 121 kfree(this); 121 122 } 122 123 } ··· 276 275 ret = register_device(name, start, len); 277 276 if (!ret) 278 277 pr_info("%s device: %#x at %#x\n", name, len, start); 278 + else 279 + kfree(name); 279 280 280 281 return ret; 281 282 }