[PATCH v2 02/14] nand: don't overwrite mtd name in nand_register()

Alexey Romanov avromanov at salutedevices.com
Tue Jan 9 18:32:14 CET 2024


We use this function in SPI NAND subsystem, which already
filled mtd->name field with "spi-nand0" string.

Signed-off-by: Alexey Romanov <avromanov at salutedevices.com>
---
 drivers/mtd/nand/core.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/nand/core.c b/drivers/mtd/nand/core.c
index f792ef844a..f67421f0cb 100644
--- a/drivers/mtd/nand/core.c
+++ b/drivers/mtd/nand/core.c
@@ -23,7 +23,7 @@
 int nand_curr_device = -1;
 
 static struct mtd_info *nand_info[CONFIG_SYS_MAX_NAND_DEVICE];
-static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][8];
+static char dev_name[CONFIG_SYS_MAX_NAND_DEVICE][16];
 static unsigned long total_nand_size; /* in kiB */
 
 /**
@@ -289,8 +289,12 @@ int nand_register(int devnum, struct mtd_info *mtd)
 
 	nand_info[devnum] = mtd;
 
-	sprintf(dev_name[devnum], "nand%d", devnum);
-	mtd->name = dev_name[devnum];
+	if (!strlen(mtd->name)) {
+		snprintf(dev_name[devnum], ARRAY_SIZE(dev_name[devnum]), "nand%d", devnum);
+		mtd->name = dev_name[devnum];
+	} else {
+		strlcpy(dev_name[devnum], mtd->name, ARRAY_SIZE(dev_name[devnum]));
+	}
 
 #ifdef CONFIG_MTD
 	/*
-- 
2.30.1



More information about the U-Boot mailing list