Skip to content

Commit 472b444

Browse files
mtd: fix cmdlinepart parser, early naming for auto-filled MTD
Commit 807f16d ("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: 807f16d ("mtd: core: set some defaults when dev.parent is set") Reported-by: Heiko Schocher <hs@denx.de> Signed-off-by: Brian Norris <computersforpeace@gmail.com> Cc: Heiko Schocher <hs@denx.de> Cc: Frans Klaver <fransklaver@gmail.com>
1 parent e488ca9 commit 472b444

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,6 @@ int add_mtd_device(struct mtd_info *mtd)
426426
mtd->erasesize_mask = (1 << mtd->erasesize_shift) - 1;
427427
mtd->writesize_mask = (1 << mtd->writesize_shift) - 1;
428428

429-
if (mtd->dev.parent) {
430-
if (!mtd->owner && mtd->dev.parent->driver)
431-
mtd->owner = mtd->dev.parent->driver->owner;
432-
if (!mtd->name)
433-
mtd->name = dev_name(mtd->dev.parent);
434-
} else {
435-
pr_debug("mtd device won't show a device symlink in sysfs\n");
436-
}
437-
438429
/* Some chips always power up locked. Unlock them now */
439430
if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) {
440431
error = mtd_unlock(mtd, 0, mtd->size);
@@ -549,6 +540,21 @@ static int mtd_add_device_partitions(struct mtd_info *mtd,
549540
return 0;
550541
}
551542

543+
/*
544+
* Set a few defaults based on the parent devices, if not provided by the
545+
* driver
546+
*/
547+
static void mtd_set_dev_defaults(struct mtd_info *mtd)
548+
{
549+
if (mtd->dev.parent) {
550+
if (!mtd->owner && mtd->dev.parent->driver)
551+
mtd->owner = mtd->dev.parent->driver->owner;
552+
if (!mtd->name)
553+
mtd->name = dev_name(mtd->dev.parent);
554+
} else {
555+
pr_debug("mtd device won't show a device symlink in sysfs\n");
556+
}
557+
}
552558

553559
/**
554560
* 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,
587593
int ret;
588594
struct mtd_partition *real_parts = NULL;
589595

596+
mtd_set_dev_defaults(mtd);
597+
590598
ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
591599
if (ret <= 0 && nr_parts && parts) {
592600
real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,

0 commit comments

Comments
 (0)