Skip to contentSkip to conversation

mtd: rawnand: ndfc: use devm_kasprintf for mtd name

PATCH Applied Rosen Penev 2 participants 2 messages Sep 9 – Sep 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: rawnand: ndfc: use devm_kasprintf for mtd name

Convert the mtd->name allocation from kasprintf() plus a manual kfree() in the error path and in ndfc_remove() to the managed devm_kasprintf() helper. The name is now released automatically with the device, removing the need for explicit cleanup.

Assisted-by opencode:hy3-free
---
 drivers/mtd/nand/raw/ndfc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/mtd/nand/raw/ndfc.c +2 -5
index d6db04d48c45..d7b119028a71 100644
@@ -162,8 +162,8 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 		return -ENODEV;
 	nand_set_flash_node(chip, flash_np);
 
-	mtd->name = kasprintf(GFP_KERNEL, "%s.%pOFn", dev_name(&ndfc->ofdev->dev),
-			      flash_np);
+	mtd->name = devm_kasprintf(&ndfc->ofdev->dev, GFP_KERNEL, "%s.%pOFn",
+				   dev_name(&ndfc->ofdev->dev), flash_np);
 	if (!mtd->name) {
 		ret = -ENOMEM;
 		goto err;
@@ -177,8 +177,6 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
 
 err:
 	of_node_put(flash_np);
-	if (ret)
-		kfree(mtd->name);
 	return ret;
 }
 
@@ -246,7 +244,6 @@ static void ndfc_remove(struct platform_device *ofdev)
 	ret = mtd_device_unregister(mtd);
 	WARN_ON(ret);
 	nand_cleanup(chip);
-	kfree(mtd->name);
 }
 
 static const struct of_device_id ndfc_match[] = {
Signature · 1 line
2.55.0
maintainer Applied
#1 lore raw
Quoted 6 lines · Rosen Penev

Convert the mtd->name allocation from kasprintf() plus a manual kfree() in the error path and in ndfc_remove() to the managed devm_kasprintf() helper. The name is now released automatically with the device, removing the need for explicit cleanup.

Applied to nand/next, thanks!

[1/1] mtd: rawnand: ndfc: use devm_kasprintf for mtd name

      commit: 5e73728a875a91fb2c7dc527f7391da0205f85b1

Patche(s) should be available on mtd/linux.git and will be part of the next PR (provided that no robot complains by then).

Kind regards,
Miquèl