From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751149AbbKBAis (ORCPT ); Sun, 1 Nov 2015 19:38:48 -0500 Received: from down.free-electrons.com ([37.187.137.238]:38872 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750704AbbKBAiq (ORCPT ); Sun, 1 Nov 2015 19:38:46 -0500 From: Boris Brezillon To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Cc: Ezequiel Garcia , Marek Vasut , Scott Wood , Josh Wu , Robert Jarzmik , Kyungmin Park , Han Xu , Stefan Agner , linux-kernel@vger.kernel.org, Boris Brezillon Subject: [PATCH v2 13/11] mtd: assign mtd->dev.of_node when creating partition devices Date: Mon, 2 Nov 2015 01:38:41 +0100 Message-Id: <1446424721-23471-1-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1446262410-45754-1-git-send-email-computersforpeace@gmail.com> References: <1446262410-45754-1-git-send-email-computersforpeace@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org MTD partitions may have been created from a DT definition, and in this case the ->of_node of the struct device embedded in mtd_info should point to the DT node that was used to create the partition. Signed-off-by: Boris Brezillon --- Hi Brian, Yet another patch that IMO should go into your "mtd: migrate 'of_node' handling to core, not in mtd_part_parser_data" series. Best Regards, Boris drivers/mtd/mtdcore.c | 17 +++++++++++++---- drivers/mtd/mtdpart.c | 3 +++ drivers/mtd/ofpart.c | 1 + include/linux/mtd/partitions.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index b1eea48..6101288 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -584,11 +585,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, const struct mtd_partition *parts, int nr_parts) { - int ret; + int ret, i; struct mtd_partition *real_parts = NULL; ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data); - if (ret <= 0 && nr_parts && parts) { + if (ret > 0) { + nr_parts = ret; + } else if (nr_parts && parts) { real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, GFP_KERNEL); if (!real_parts) @@ -604,7 +607,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, ret = 0; } - ret = mtd_add_device_partitions(mtd, real_parts, ret); + ret = mtd_add_device_partitions(mtd, real_parts, nr_parts); if (ret) goto out; @@ -623,7 +626,13 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, } out: - kfree(real_parts); + if (real_parts) { + for (i = 0; i < nr_parts; i++) + of_node_put(real_parts[i].of_node); + + kfree(real_parts); + } + return ret; } EXPORT_SYMBOL_GPL(mtd_device_parse_register); diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index f8ba153..95f3a0d 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -319,6 +320,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) static inline void free_partition(struct mtd_part *p) { + of_node_put(mtd_get_of_node(&p->mtd)); kfree(p->mtd.name); kfree(p); } @@ -391,6 +393,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.dev.parent = IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) ? &master->dev : master->dev.parent; + mtd_set_of_node(&slave->mtd, of_node_get(part->of_node)); slave->mtd._read = part_read; slave->mtd._write = part_write; diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c index f78d2ae..5c64e04 100644 --- a/drivers/mtd/ofpart.c +++ b/drivers/mtd/ofpart.c @@ -111,6 +111,7 @@ static int parse_ofpart_partitions(struct mtd_info *master, if (of_get_property(pp, "lock", &len)) (*pparts)[i].mask_flags |= MTD_POWERUP_LOCK; + (*pparts)[i].of_node = of_node_get(pp); i++; } diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h index 773975a..282644c 100644 --- a/include/linux/mtd/partitions.h +++ b/include/linux/mtd/partitions.h @@ -42,6 +42,7 @@ struct mtd_partition { uint64_t offset; /* offset within the master MTD space */ uint32_t mask_flags; /* master MTD flags to mask out for this partition */ struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only) */ + struct device_node *of_node; /* OF node attached to the partition */ }; #define MTDPART_OFS_RETAIN (-3) -- 2.1.4