mtd: fix cmdlinepart parser, early naming for auto-filled MTD

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Mon Jan 4 10:59:02 PST 2016


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=472b444eef934eb7e90334efdd7fc7954cfe5132
Commit:     472b444eef934eb7e90334efdd7fc7954cfe5132
Parent:     e488ca9f8d4f62c2dc36bfa5c32f68e7f05ab381
Author:     Brian Norris <computersforpeace at gmail.com>
AuthorDate: Fri Dec 11 15:58:01 2015 -0800
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Mon Jan 4 10:54:18 2016 -0800

    mtd: fix cmdlinepart parser, early naming for auto-filled MTD
    
    Commit 807f16d4db95 ("mtd: core: set some defaults when dev.parent is
    set") attempted to provide some default settings for MTDs that
     (a) assign the parent device and
     (b) don't provide their own name or owner
    
    However, this isn't a perfect drop-in replacement for the boilerplate
    found in some drivers, because the MTD name is used by partition
    parsers like cmdlinepart, but the name isn't set until add_mtd_device(),
    after the parsing is completed. This means cmdlinepart sees a NULL name
    and therefore will not work properly.
    
    Fix this by moving the default name and owner assignment to be first in
    the MTD registration process.
    
    [Note: this does not fix all reported issues, particularly with NAND
    drivers. Will require an additional fix for drivers/mtd/nand/]
    
    Fixes: 807f16d4db95 ("mtd: core: set some defaults when dev.parent is set")
    Reported-by: Heiko Schocher <hs at denx.de>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
    Cc: Heiko Schocher <hs at denx.de>
    Cc: Frans Klaver <fransklaver at gmail.com>
---
 drivers/mtd/mtdcore.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 95c13b2..ffa2884 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -426,15 +426,6 @@ int add_mtd_device(struct mtd_info *mtd)
 	mtd->erasesize_mask = (1 << mtd->erasesize_shift) - 1;
 	mtd->writesize_mask = (1 << mtd->writesize_shift) - 1;
 
-	if (mtd->dev.parent) {
-		if (!mtd->owner && mtd->dev.parent->driver)
-			mtd->owner = mtd->dev.parent->driver->owner;
-		if (!mtd->name)
-			mtd->name = dev_name(mtd->dev.parent);
-	} else {
-		pr_debug("mtd device won't show a device symlink in sysfs\n");
-	}
-
 	/* Some chips always power up locked. Unlock them now */
 	if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) {
 		error = mtd_unlock(mtd, 0, mtd->size);
@@ -549,6 +540,21 @@ static int mtd_add_device_partitions(struct mtd_info *mtd,
 	return 0;
 }
 
+/*
+ * Set a few defaults based on the parent devices, if not provided by the
+ * driver
+ */
+static void mtd_set_dev_defaults(struct mtd_info *mtd)
+{
+	if (mtd->dev.parent) {
+		if (!mtd->owner && mtd->dev.parent->driver)
+			mtd->owner = mtd->dev.parent->driver->owner;
+		if (!mtd->name)
+			mtd->name = dev_name(mtd->dev.parent);
+	} else {
+		pr_debug("mtd device won't show a device symlink in sysfs\n");
+	}
+}
 
 /**
  * mtd_device_parse_register - parse partitions and register an MTD device.
@@ -587,6 +593,8 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
 	int ret;
 	struct mtd_partition *real_parts = NULL;
 
+	mtd_set_dev_defaults(mtd);
+
 	ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
 	if (ret <= 0 && nr_parts && parts) {
 		real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,



More information about the linux-mtd-cvs mailing list