[PATCH] mtd: Ensure NVMEM layouts get their of_node
Miquel Raynal
miquel.raynal at bootlin.com
Wed Oct 4 15:04:37 PDT 2023
All the nvmem-layouts logic expects an of_node to be available. When mtd
started registering nvmem devices, the exact exposure was not yet
decided and thus the no_of_node field was set to 1 to avoid exposing
"too much". This has been lowered since we want children nodes of mtd
devices with the "nvmem-cells" compatible to be actually registered in
NVMEM. This is now also the case of the nvmem-layout containers.
Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
drivers/mtd/mtdcore.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 061745acb9a7..60b670c42be5 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -543,6 +543,13 @@ static int mtd_nvmem_reg_read(void *priv, unsigned int offset,
return retlen == bytes ? 0 : -EIO;
}
+static bool mtd_contains_nvmem_layout(struct mtd_info *mtd)
+{
+ /* of_find_node_by_name() calls of_node_put() on the starting node */
+ of_node_get(mtd->dev.of_node);
+ return of_find_node_by_name(mtd->dev.of_node, "nvmem-layout");
+}
+
static int mtd_nvmem_add(struct mtd_info *mtd)
{
struct device_node *node = mtd_get_of_node(mtd);
@@ -559,7 +566,8 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
config.read_only = true;
config.root_only = true;
config.ignore_wp = true;
- config.no_of_node = !of_device_is_compatible(node, "nvmem-cells");
+ config.no_of_node = !of_device_is_compatible(node, "nvmem-cells") ||
+ !mtd_contains_nvmem_layout(mtd);
config.priv = mtd;
mtd->nvmem = nvmem_register(&config);
--
2.34.1
More information about the linux-mtd
mailing list