Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0dd77a7 authored by YueHaibing's avatar YueHaibing Committed by Boris Brezillon
Browse files

mtd: docg3: fix a possible memory leak of mtd->name



In case DOC_CHIPID_G3, mtd->name is not freed in err handling path,
which is alloced by kasprintf(). Fix this by using devm_kasprintf().

Fixes: ae9d4934 ("mtd: docg3: add multiple floor support")
Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
Signed-off-by: default avatarBoris Brezillon <bbrezillon@kernel.org>
parent f7fd818c
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -1767,7 +1767,7 @@ static int __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)

	switch (chip_id) {
	case DOC_CHIPID_G3:
		mtd->name = kasprintf(GFP_KERNEL, "docg3.%d",
		mtd->name = devm_kasprintf(docg3->dev, GFP_KERNEL, "docg3.%d",
					   docg3->device_id);
		if (!mtd->name)
			return -ENOMEM;
@@ -1886,7 +1886,6 @@ static void doc_release_device(struct mtd_info *mtd)
	mtd_device_unregister(mtd);
	kfree(docg3->bbt);
	kfree(docg3);
	kfree(mtd->name);
	kfree(mtd);
}