From 15a1e44586d4d3e520c72413a9f3dd926c5a3aa7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 28 Aug 2018 08:19:15 -0600 Subject: [PATCH] drivers/mtd/ftl.c: Reduce size of stack buffer from 64 to a maximum size as determined from NAME_MAX --- drivers/mtd/ftl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index e97296d55a..fbba8cbf9f 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -60,10 +61,18 @@ * Pre-processor Definitions ****************************************************************************/ +/* Check if read/write buffer support is needed */ + #if defined(CONFIG_FTL_READAHEAD) || defined(CONFIG_FTL_WRITEBUFFER) # define FTL_HAVE_RWBUFFER 1 #endif +/* The maximum length of the device name paths is the maximum length of a + * name plus 5 for the the length of "/dev/" and a NUL terminator. + */ + +#define DEV_NAME_MAX (NAME_MAX + 5) + /**************************************************************************** * Private Types ****************************************************************************/ @@ -515,7 +524,7 @@ static int ftl_ioctl(FAR struct inode *inode, int cmd, unsigned long arg) int ftl_initialize_by_name(FAR const char *name, FAR struct mtd_dev_s *mtd) { struct ftl_struct_s *dev; - char devname[64]; + char devname[DEV_NAME_MAX]; int ret = -ENOMEM; #ifdef CONFIG_DEBUG_FEATURES @@ -597,7 +606,7 @@ int ftl_initialize_by_name(FAR const char *name, FAR struct mtd_dev_s *mtd) /* Create a MTD block device name */ - snprintf(devname, 64, "/dev/mtd%s", name); + snprintf(devname, DEV_NAME_MAX, "/dev/mtd%s", name); /* Inode private data is a reference to the FTL device structure */