From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Tudor Ambarus <Tudor.Ambarus@microchip.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>
Cc: <linux-mtd@lists.infradead.org>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Mark Brown <broonie@kernel.org>,
Boris Brezillon <boris.brezillon@collabora.com>,
Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
Bernhard Frauendienst <kernel@nospam.obeliks.de>,
Miquel Raynal <miquel.raynal@bootlin.com>
Subject: [PATCH v5 3/4] mtd: Add get_mtd_device_by_node() helper
Date: Wed, 27 Nov 2019 11:55:21 +0100 [thread overview]
Message-ID: <20191127105522.31445-4-miquel.raynal@bootlin.com> (raw)
In-Reply-To: <20191127105522.31445-1-miquel.raynal@bootlin.com>
From: Bernhard Frauendienst <kernel@nospam.obeliks.de>
Add an helper to retrieve a MTD device by its OF node. Since drivers can
assign arbitrary names to MTD devices in the absence of a 'label' DT
property, there is no other reliable way to retrieve a MTD device for a
given OF node.
Signed-off-by: Bernhard Frauendienst <kernel@nospam.obeliks.de>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
[<miquel.raynal@bootlin.com>: light internals rework]
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
drivers/mtd/mtdcore.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/mtd/mtd.h | 2 ++
2 files changed, 40 insertions(+)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 76b4264936ff..5a94a2c0a6de 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -985,6 +985,44 @@ struct mtd_info *get_mtd_device_nm(const char *name)
}
EXPORT_SYMBOL_GPL(get_mtd_device_nm);
+/**
+ * get_mtd_device_by_node - obtain a validated handle for an MTD device
+ * by of_node
+ * @of_node: OF node of MTD device to open
+ *
+ * This function returns an MTD device structure in case of success,
+ * an error code otherwise.
+ */
+struct mtd_info *get_mtd_device_by_node(const struct device_node *of_node)
+{
+ struct mtd_info *mtd;
+ bool found = false;
+ int ret;
+
+ mutex_lock(&mtd_table_mutex);
+
+ mtd_for_each_device(mtd) {
+ if (of_node == mtd->dev.of_node) {
+ found = true;
+ break;
+ }
+ }
+
+ if (found)
+ ret = __get_mtd_device(mtd);
+
+ mutex_unlock(&mtd_table_mutex);
+
+ if (!found)
+ return ERR_PTR(-ENODEV);
+
+ if (ret)
+ return ERR_PTR(ret);
+
+ return mtd;
+}
+EXPORT_SYMBOL_GPL(get_mtd_device_by_node);
+
void put_mtd_device(struct mtd_info *mtd)
{
mutex_lock(&mtd_table_mutex);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 677768b21a1d..0f25c476a1a3 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -573,6 +573,8 @@ extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
extern int __get_mtd_device(struct mtd_info *mtd);
extern void __put_mtd_device(struct mtd_info *mtd);
extern struct mtd_info *get_mtd_device_nm(const char *name);
+extern struct mtd_info *get_mtd_device_by_node(
+ const struct device_node *of_node);
extern void put_mtd_device(struct mtd_info *mtd);
--
2.20.1
next prev parent reply other threads:[~2019-11-27 10:55 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-27 10:55 [PATCH v5 0/4] MTD concat Miquel Raynal
2019-11-27 10:55 ` [PATCH v5 1/4] dt-bindings: mtd: Describe MTD partitions concatenation Miquel Raynal
2019-11-27 10:55 ` [PATCH v5 2/4] mtd: concat: Fix a comment referring to an unknown symbol Miquel Raynal
2019-11-27 10:55 ` Miquel Raynal [this message]
2019-11-27 10:55 ` [PATCH v5 4/4] mtd: Add driver for concatenating devices Miquel Raynal
2019-12-04 9:58 ` Vignesh Raghavendra
2019-12-04 10:17 ` Miquel Raynal
2019-12-04 12:55 ` Vignesh Raghavendra
2019-12-09 10:35 ` Boris Brezillon
2020-01-14 9:24 ` Miquel Raynal
2020-01-14 17:46 ` Rob Herring
2020-01-14 18:10 ` Miquel Raynal
2020-01-14 21:59 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191127105522.31445-4-miquel.raynal@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=Tudor.Ambarus@microchip.com \
--cc=boris.brezillon@collabora.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@nospam.obeliks.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=paul.kocialkowski@bootlin.com \
--cc=richard@nod.at \
--cc=robh+dt@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).