[PATCH] kernel: replace downstream get_mtd_device_by_node() implementation

Rafał Miłecki zajec5 at gmail.com
Wed Aug 17 14:20:45 PDT 2022


From: Rafał Miłecki <rafal at milecki.pl>

Use upstream of_get_mtd_device_by_node() which should behave pretty much
the same. Implementation differences:

get_mtd_device_by_node()  of_get_mtd_device_by_node()
----                      ----
np->dev.of_node           mtd_get_of_node(np)
-EPROBE_DEFER             -ENODEV

Cc: Bernhard Frauendienst <openwrt at nospam.obeliks.de>
Cc: Bernhard Frauendienst <kernel at nospam.obeliks.de>
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 ...-mtd-core-add-get_mtd_device_by_node.patch | 75 -------------------
 ...cat-add-dt-driver-for-concat-devices.patch |  2 +-
 ...-mtd-core-add-get_mtd_device_by_node.patch | 75 -------------------
 ...cat-add-dt-driver-for-concat-devices.patch |  2 +-
 4 files changed, 2 insertions(+), 152 deletions(-)
 delete mode 100644 target/linux/generic/pending-5.10/495-mtd-core-add-get_mtd_device_by_node.patch
 delete mode 100644 target/linux/generic/pending-5.15/495-mtd-core-add-get_mtd_device_by_node.patch

diff --git a/target/linux/generic/pending-5.10/495-mtd-core-add-get_mtd_device_by_node.patch b/target/linux/generic/pending-5.10/495-mtd-core-add-get_mtd_device_by_node.patch
deleted file mode 100644
index 66017e1648..0000000000
--- a/target/linux/generic/pending-5.10/495-mtd-core-add-get_mtd_device_by_node.patch
+++ /dev/null
@@ -1,75 +0,0 @@
-From 1bd1b740f208d1cf4071932cc51860d37266c402 Mon Sep 17 00:00:00 2001
-From: Bernhard Frauendienst <kernel at nospam.obeliks.de>
-Date: Sat, 1 Sep 2018 00:30:11 +0200
-Subject: [PATCH 495/497] mtd: core: add get_mtd_device_by_node
-
-Add function to retrieve a mtd device by its OF node. Since drivers can
-assign arbitrary names to mtd devices in the absence of a label
-property, there is no other reliable way to retrieve a mtd device for a
-given OF node.
-
-Signed-off-by: Bernhard Frauendienst <kernel at nospam.obeliks.de>
-Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
----
- drivers/mtd/mtdcore.c   | 38 ++++++++++++++++++++++++++++++++++++++
- include/linux/mtd/mtd.h |  2 ++
- 2 files changed, 40 insertions(+)
-
---- a/drivers/mtd/mtdcore.c
-+++ b/drivers/mtd/mtdcore.c
-@@ -1145,6 +1145,44 @@ out_unlock:
- }
- 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 MTD device description structure in case of
-+ *	success and an error code in case of failure.
-+ */
-+struct mtd_info *get_mtd_device_by_node(const struct device_node *of_node)
-+{
-+	int err = -ENODEV;
-+	struct mtd_info *mtd = NULL, *other;
-+
-+	mutex_lock(&mtd_table_mutex);
-+
-+	mtd_for_each_device(other) {
-+		if (of_node == other->dev.of_node) {
-+			mtd = other;
-+			break;
-+		}
-+	}
-+
-+	if (!mtd)
-+		goto out_unlock;
-+
-+	err = __get_mtd_device(mtd);
-+	if (err)
-+		goto out_unlock;
-+
-+	mutex_unlock(&mtd_table_mutex);
-+	return mtd;
-+
-+out_unlock:
-+	mutex_unlock(&mtd_table_mutex);
-+	return ERR_PTR(err);
-+}
-+EXPORT_SYMBOL_GPL(get_mtd_device_by_node);
-+
- void put_mtd_device(struct mtd_info *mtd)
- {
- 	mutex_lock(&mtd_table_mutex);
---- a/include/linux/mtd/mtd.h
-+++ b/include/linux/mtd/mtd.h
-@@ -697,6 +697,8 @@ extern int __get_mtd_device(struct mtd_i
- extern void __put_mtd_device(struct mtd_info *mtd);
- extern struct mtd_info *of_get_mtd_device_by_node(struct device_node *np);
- 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);
- 
- static inline uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
diff --git a/target/linux/generic/pending-5.10/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch b/target/linux/generic/pending-5.10/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
index 058cab09e5..9b938a43f8 100644
--- a/target/linux/generic/pending-5.10/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
+++ b/target/linux/generic/pending-5.10/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
@@ -165,7 +165,7 @@ Signed-off-by: Bernhard Frauendienst <kernel at nospam.obeliks.de>
 +	platform_set_drvdata(pdev, info);
 +
 +	of_for_each_phandle(&it, err, node, "devices", NULL, 0) {
-+		mtd = get_mtd_device_by_node(it.node);
++		mtd = of_get_mtd_device_by_node(it.node);
 +		if (IS_ERR(mtd)) {
 +			of_node_put(it.node);
 +			err = -EPROBE_DEFER;
diff --git a/target/linux/generic/pending-5.15/495-mtd-core-add-get_mtd_device_by_node.patch b/target/linux/generic/pending-5.15/495-mtd-core-add-get_mtd_device_by_node.patch
deleted file mode 100644
index 3e14a1dd31..0000000000
--- a/target/linux/generic/pending-5.15/495-mtd-core-add-get_mtd_device_by_node.patch
+++ /dev/null
@@ -1,75 +0,0 @@
-From 1bd1b740f208d1cf4071932cc51860d37266c402 Mon Sep 17 00:00:00 2001
-From: Bernhard Frauendienst <kernel at nospam.obeliks.de>
-Date: Sat, 1 Sep 2018 00:30:11 +0200
-Subject: [PATCH 495/497] mtd: core: add get_mtd_device_by_node
-
-Add function to retrieve a mtd device by its OF node. Since drivers can
-assign arbitrary names to mtd devices in the absence of a label
-property, there is no other reliable way to retrieve a mtd device for a
-given OF node.
-
-Signed-off-by: Bernhard Frauendienst <kernel at nospam.obeliks.de>
-Reviewed-by: Miquel Raynal <miquel.raynal at bootlin.com>
----
- drivers/mtd/mtdcore.c   | 38 ++++++++++++++++++++++++++++++++++++++
- include/linux/mtd/mtd.h |  2 ++
- 2 files changed, 40 insertions(+)
-
---- a/drivers/mtd/mtdcore.c
-+++ b/drivers/mtd/mtdcore.c
-@@ -1302,6 +1302,44 @@ out_unlock:
- }
- 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 MTD device description structure in case of
-+ *	success and an error code in case of failure.
-+ */
-+struct mtd_info *get_mtd_device_by_node(const struct device_node *of_node)
-+{
-+	int err = -ENODEV;
-+	struct mtd_info *mtd = NULL, *other;
-+
-+	mutex_lock(&mtd_table_mutex);
-+
-+	mtd_for_each_device(other) {
-+		if (of_node == other->dev.of_node) {
-+			mtd = other;
-+			break;
-+		}
-+	}
-+
-+	if (!mtd)
-+		goto out_unlock;
-+
-+	err = __get_mtd_device(mtd);
-+	if (err)
-+		goto out_unlock;
-+
-+	mutex_unlock(&mtd_table_mutex);
-+	return mtd;
-+
-+out_unlock:
-+	mutex_unlock(&mtd_table_mutex);
-+	return ERR_PTR(err);
-+}
-+EXPORT_SYMBOL_GPL(get_mtd_device_by_node);
-+
- void put_mtd_device(struct mtd_info *mtd)
- {
- 	mutex_lock(&mtd_table_mutex);
---- a/include/linux/mtd/mtd.h
-+++ b/include/linux/mtd/mtd.h
-@@ -704,6 +704,8 @@ extern int __get_mtd_device(struct mtd_i
- extern void __put_mtd_device(struct mtd_info *mtd);
- extern struct mtd_info *of_get_mtd_device_by_node(struct device_node *np);
- 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);
- 
- static inline uint64_t mtdpart_get_offset(const struct mtd_info *mtd)
diff --git a/target/linux/generic/pending-5.15/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch b/target/linux/generic/pending-5.15/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
index 321680154d..e0cbc4508b 100644
--- a/target/linux/generic/pending-5.15/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
+++ b/target/linux/generic/pending-5.15/497-mtd-mtdconcat-add-dt-driver-for-concat-devices.patch
@@ -165,7 +165,7 @@ Signed-off-by: Bernhard Frauendienst <kernel at nospam.obeliks.de>
 +	platform_set_drvdata(pdev, info);
 +
 +	of_for_each_phandle(&it, err, node, "devices", NULL, 0) {
-+		mtd = get_mtd_device_by_node(it.node);
++		mtd = of_get_mtd_device_by_node(it.node);
 +		if (IS_ERR(mtd)) {
 +			of_node_put(it.node);
 +			err = -EPROBE_DEFER;
-- 
2.34.1




More information about the openwrt-devel mailing list