Messages in this thread Patch in this message | | | From | Frans Klaver <> | Subject | [PATCH v2 02/60] mtd: core: set some defaults when dev.parent is set | Date | Wed, 10 Jun 2015 22:38:16 +0200 |
| |
If a parent device is set, add_mtd_device() has enough knowledge to fill in some sane default values for the module name and owner. Do so if they aren't already set.
Signed-off-by: Frans Klaver <fransklaver@gmail.com>
--- v1..v2 - Apparently we can get here without a driver set, causing a NULL dereference[0]. Check that a driver is there before copying the owner. It does mean that parent devices that don't seem to be having a driver lying around still can't produce an owner. I suppose the effect is not much different from it was before. - Change wording of debug message to mention the fact we're talking about parent device symlinks here.
[0] https://lkml.org/lkml/2015/4/16/15 --- drivers/mtd/mtdcore.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index d7967cc..0bd1761 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -413,6 +413,15 @@ 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); -- 2.4.0
| |