From 00d7e84af6d857031f9dfe00fe0c2735ed9ada3b Mon Sep 17 00:00:00 2001 From: John Crispin Date: Sun, 30 Mar 2014 09:14:58 +0000 Subject: [PATCH] mtd: improve mtd detection Signed-off-by: John Crispin SVN-Revision: 40301 --- package/system/mtd/src/mtd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package/system/mtd/src/mtd.c b/package/system/mtd/src/mtd.c index 604ca28ae2..7b80193b44 100644 --- a/package/system/mtd/src/mtd.c +++ b/package/system/mtd/src/mtd.c @@ -67,10 +67,12 @@ int mtd_open(const char *mtd, bool block) int i; int ret; int flags = O_RDWR | O_SYNC; + char name[PATH_MAX]; + snprintf(name, sizeof(name), "\"%s\"", mtd); if ((fp = fopen("/proc/mtd", "r"))) { while (fgets(dev, sizeof(dev), fp)) { - if (sscanf(dev, "mtd%d:", &i) && strstr(dev, mtd)) { + if (sscanf(dev, "mtd%d:", &i) && strstr(dev, name)) { snprintf(dev, sizeof(dev), "/dev/mtd%s/%d", (block ? "block" : ""), i); if ((ret=open(dev, flags))<0) { snprintf(dev, sizeof(dev), "/dev/mtd%s%d", (block ? "block" : ""), i); -- 2.30.2