diff mbox series

mtd: Ensure NVMEM layouts get their of_node

Message ID 20231004220437.405959-1-miquel.raynal@bootlin.com
State New
Headers show
Series mtd: Ensure NVMEM layouts get their of_node | expand

Commit Message

Miquel Raynal Oct. 4, 2023, 10:04 p.m. UTC
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@bootlin.com>
---
 drivers/mtd/mtdcore.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Rafał Miłecki Oct. 6, 2023, 8:56 a.m. UTC | #1
Hi Miquel,

On 5.10.2023 00:04, Miquel Raynal wrote:
> 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@bootlin.com>

I already sent a patch for that and it goes even further by completely
dropping "no_of_node" which isn't needed anymore. See:
[PATCH] Revert "nvmem: add new config option"
https://lore.kernel.org/lkml/ba3c419a-6511-480a-b5f2-6c418f9c02e7@gmail.com/t/

It's waiting for over 2 months already and just recently I re-asked
Srini to queue it so hopefully it won't miss another merge window.


> ---
>   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);
diff mbox series

Patch

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