We use this function in SPI NAND subsystem, which already filled mtd->name field with "spi-nand0" string.
Signed-off-by: Alexey Romanov <avroma...@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 ff298e3a0f..5a63e74ccb 100644 --- a/drivers/mtd/nand/core.c +++ b/drivers/mtd/nand/core.c @@ -22,7 +22,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 */ /** @@ -288,8 +288,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