UBI: fix mtd device string parsing

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Tue Jan 8 02:59:03 EST 2008


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=d1f3dd6cc00f5bf744118fb2820ecdf09a1f4b73
Commit:     d1f3dd6cc00f5bf744118fb2820ecdf09a1f4b73
Parent:     783b273afab43437dca731a229d53d72faf77fd3
Author:     Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
AuthorDate: Tue Dec 25 19:17:00 2007 +0200
Committer:  Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
CommitDate: Wed Dec 26 19:15:17 2007 +0200

    UBI: fix mtd device string parsing
    
    UBI allows to specify MTD device name or number when the module is being
    loaded. When parsing MTD device identity string, it first tries to treat
    it as device NAME, and if that fails, it treats it as device number.
    
    Make it vice-versa as this is more logical and makes less troubles when
    you have an MTD device named "1" and try to load mtd1 which has different
    name. This is especially easy to hit when gluebi is enabled.
    
    Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy at nokia.com>
---
 drivers/mtd/ubi/build.c |   36 ++++++++++++------------------------
 1 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 6ac1339..0ed8105 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -867,38 +867,26 @@ static void ltree_entry_ctor(struct kmem_cache *cache, void *obj)
  * find_mtd_device - open an MTD device by its name or number.
  * @mtd_dev: name or number of the device
  *
- * This function tries to open and MTD device with name @mtd_dev, and if it
- * fails, then it tries to interpret the @mtd_dev string as an ASCII-coded
- * integer and open an MTD device with this number. Returns MTD device
- * description object in case of success and a negative error code in case of
- * failure.
+ * This function tries to open and MTD device described by @mtd_dev string,
+ * which is first treated as an ASCII number, and if it is not true, it is
+ * treated as MTD device name. Returns MTD device description object in case of
+ * success and a negative error code in case of failure.
  */
 static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
 {
 	struct mtd_info *mtd;
+	int mtd_num;
+	char *endp;
 
-	mtd = get_mtd_device_nm(mtd_dev);
-	if (IS_ERR(mtd)) {
-		int mtd_num;
-		char *endp;
-
-		if (PTR_ERR(mtd) != -ENODEV)
-			return mtd;
-
+	mtd_num = simple_strtoul(mtd_dev, &endp, 0);
+	if (*endp != '\0' || mtd_dev == endp) {
 		/*
-		 * Probably this is not MTD device name but MTD device number -
-		 * check this out.
+		 * This does not look like an ASCII integer, probably this is
+		 * MTD device name.
 		 */
-		mtd_num = simple_strtoul(mtd_dev, &endp, 0);
-		if (*endp != '\0' || mtd_dev == endp) {
-			ubi_err("incorrect MTD device: \"%s\"", mtd_dev);
-			return ERR_PTR(-ENODEV);
-		}
-
+		mtd = get_mtd_device_nm(mtd_dev);
+	} else
 		mtd = get_mtd_device(NULL, mtd_num);
-		if (IS_ERR(mtd))
-			return mtd;
-	}
 
 	return mtd;
 }



More information about the linux-mtd-cvs mailing list