Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965370AbbFJU4G (ORCPT ); Wed, 10 Jun 2015 16:56:06 -0400 Received: from mail-wg0-f67.google.com ([74.125.82.67]:33846 "EHLO mail-wg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751528AbbFJUjG (ORCPT ); Wed, 10 Jun 2015 16:39:06 -0400 From: Frans Klaver To: Brian Norris Cc: Frans Klaver , David Woodhouse , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH v2 02/60] mtd: core: set some defaults when dev.parent is set Date: Wed, 10 Jun 2015 22:38:16 +0200 Message-Id: <1433968754-10651-3-git-send-email-fransklaver@gmail.com> X-Mailer: git-send-email 2.4.0 In-Reply-To: <1433968754-10651-1-git-send-email-fransklaver@gmail.com> References: <1433968754-10651-1-git-send-email-fransklaver@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1806 Lines: 49 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/