@@ -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);
@@ -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);