[PATCH] nvmem: fix issue within nvmem_register with fixed-layout.

Catalin Popescu posted 1 patch 2 years ago
drivers/nvmem/core.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
[PATCH] nvmem: fix issue within nvmem_register with fixed-layout.
Posted by Catalin Popescu 2 years ago
fixed-layout is natively supported by NVMEM framework.
Yet, it's not been declared as a supported layout. As a
result, nvmem_register always returns -EPROBE_DEFER if
configuration has no layout and the NVMEM provider DT
uses a fixed layout.

As a fix, declare fixed-layout as a supported layout
and use add_cells callback to parse the cells. This adds
consistency over layouts parsing as fixed-layout parsing
is handled in the same way than others nvmem layouts.

Signed-off-by: Catalin Popescu <catalin.popescu@leica-geosystems.com>
---
 drivers/nvmem/core.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index bf42b7e826db..3467c94207e8 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -746,7 +746,9 @@ static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
 	return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node);
 }
 
-static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
+static int nvmem_add_cells_from_fixed_layout(struct device *dev,
+					     struct nvmem_device *nvmem,
+					     struct nvmem_layout *layout)
 {
 	struct device_node *layout_np;
 	int err = 0;
@@ -755,8 +757,7 @@ static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
 	if (!layout_np)
 		return 0;
 
-	if (of_device_is_compatible(layout_np, "fixed-layout"))
-		err = nvmem_add_cells_from_dt(nvmem, layout_np);
+	err = nvmem_add_cells_from_dt(nvmem, layout_np);
 
 	of_node_put(layout_np);
 
@@ -1003,10 +1004,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 			goto err_remove_cells;
 	}
 
-	rval = nvmem_add_cells_from_fixed_layout(nvmem);
-	if (rval)
-		goto err_remove_cells;
-
 	rval = nvmem_add_cells_from_layout(nvmem);
 	if (rval)
 		goto err_remove_cells;
@@ -2126,6 +2123,19 @@ const char *nvmem_dev_name(struct nvmem_device *nvmem)
 }
 EXPORT_SYMBOL_GPL(nvmem_dev_name);
 
+static const struct of_device_id fixed_layout_of_match_table[] = {
+	{ .compatible = "fixed-layout", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, fixed_layout_of_match_table);
+
+static struct nvmem_layout fixed_layout = {
+	.name = "NVMEM fixed layout",
+	.of_match_table = fixed_layout_of_match_table,
+	.add_cells = nvmem_add_cells_from_fixed_layout,
+};
+module_nvmem_layout_driver(fixed_layout);
+
 static int __init nvmem_init(void)
 {
 	return bus_register(&nvmem_bus_type);
-- 
2.34.1
Re: [PATCH] nvmem: fix issue within nvmem_register with fixed-layout.
Posted by POPESCU Catalin 2 years ago
Adding more people.

On 30.11.23 17:29, Catalin Popescu wrote:
> fixed-layout is natively supported by NVMEM framework.
> Yet, it's not been declared as a supported layout. As a
> result, nvmem_register always returns -EPROBE_DEFER if
> configuration has no layout and the NVMEM provider DT
> uses a fixed layout.
>
> As a fix, declare fixed-layout as a supported layout
> and use add_cells callback to parse the cells. This adds
> consistency over layouts parsing as fixed-layout parsing
> is handled in the same way than others nvmem layouts.
>
> Signed-off-by: Catalin Popescu <catalin.popescu@leica-geosystems.com>
> ---
>   drivers/nvmem/core.c | 24 +++++++++++++++++-------
>   1 file changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index bf42b7e826db..3467c94207e8 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -746,7 +746,9 @@ static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
>   	return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node);
>   }
>   
> -static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
> +static int nvmem_add_cells_from_fixed_layout(struct device *dev,
> +					     struct nvmem_device *nvmem,
> +					     struct nvmem_layout *layout)
>   {
>   	struct device_node *layout_np;
>   	int err = 0;
> @@ -755,8 +757,7 @@ static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
>   	if (!layout_np)
>   		return 0;
>   
> -	if (of_device_is_compatible(layout_np, "fixed-layout"))
> -		err = nvmem_add_cells_from_dt(nvmem, layout_np);
> +	err = nvmem_add_cells_from_dt(nvmem, layout_np);
>   
>   	of_node_put(layout_np);
>   
> @@ -1003,10 +1004,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   			goto err_remove_cells;
>   	}
>   
> -	rval = nvmem_add_cells_from_fixed_layout(nvmem);
> -	if (rval)
> -		goto err_remove_cells;
> -
>   	rval = nvmem_add_cells_from_layout(nvmem);
>   	if (rval)
>   		goto err_remove_cells;
> @@ -2126,6 +2123,19 @@ const char *nvmem_dev_name(struct nvmem_device *nvmem)
>   }
>   EXPORT_SYMBOL_GPL(nvmem_dev_name);
>   
> +static const struct of_device_id fixed_layout_of_match_table[] = {
> +	{ .compatible = "fixed-layout", },
> +	{},
> +};
> +MODULE_DEVICE_TABLE(of, fixed_layout_of_match_table);
> +
> +static struct nvmem_layout fixed_layout = {
> +	.name = "NVMEM fixed layout",
> +	.of_match_table = fixed_layout_of_match_table,
> +	.add_cells = nvmem_add_cells_from_fixed_layout,
> +};
> +module_nvmem_layout_driver(fixed_layout);
> +
>   static int __init nvmem_init(void)
>   {
>   	return bus_register(&nvmem_bus_type);


Re: [PATCH] nvmem: fix issue within nvmem_register with fixed-layout.
Posted by Miquel Raynal 2 years ago
Hi Catalin,

+ GKH
+ Luca (who initially reported this issue)

catalin.popescu@leica-geosystems.com wrote on Tue, 5 Dec 2023 08:48:27
+0000:

> Adding more people.
> 
> On 30.11.23 17:29, Catalin Popescu wrote:
> > fixed-layout is natively supported by NVMEM framework.
> > Yet, it's not been declared as a supported layout. As a
> > result, nvmem_register always returns -EPROBE_DEFER if
> > configuration has no layout and the NVMEM provider DT
> > uses a fixed layout.
> >
> > As a fix, declare fixed-layout as a supported layout
> > and use add_cells callback to parse the cells. This adds
> > consistency over layouts parsing as fixed-layout parsing
> > is handled in the same way than others nvmem layouts.

I believe this patch (not taken yet) should fix your issue and should be
queued to fixes.

Link: https://lore.kernel.org/lkml/20231124193814.360552-1-miquel.raynal@bootlin.com/

However I like your approach which should probably be taken into
consideration for the next cycle, as I think it fits Rafal's
original idea pretty well.

> >
> > Signed-off-by: Catalin Popescu <catalin.popescu@leica-geosystems.com>
> > ---
> >   drivers/nvmem/core.c | 24 +++++++++++++++++-------
> >   1 file changed, 17 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> > index bf42b7e826db..3467c94207e8 100644
> > --- a/drivers/nvmem/core.c
> > +++ b/drivers/nvmem/core.c
> > @@ -746,7 +746,9 @@ static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
> >   	return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node);
> >   }
> >   
> > -static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
> > +static int nvmem_add_cells_from_fixed_layout(struct device *dev,
> > +					     struct nvmem_device *nvmem,
> > +					     struct nvmem_layout *layout)

I've sent another series (on top of the fix mentioned above) to
simplify a bit this list of parameters, so both will conflict. But that
will be easy to solve.

Link: https://lore.kernel.org/lkml/20231129163737.698317-1-miquel.raynal@bootlin.com/

> >   {
> >   	struct device_node *layout_np;
> >   	int err = 0;
> > @@ -755,8 +757,7 @@ static int nvmem_add_cells_from_fixed_layout(struct nvmem_device *nvmem)
> >   	if (!layout_np)
> >   		return 0;
> >   
> > -	if (of_device_is_compatible(layout_np, "fixed-layout"))
> > -		err = nvmem_add_cells_from_dt(nvmem, layout_np);
> > +	err = nvmem_add_cells_from_dt(nvmem, layout_np);
> >   
> >   	of_node_put(layout_np);
> >   
> > @@ -1003,10 +1004,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> >   			goto err_remove_cells;
> >   	}
> >   
> > -	rval = nvmem_add_cells_from_fixed_layout(nvmem);
> > -	if (rval)
> > -		goto err_remove_cells;
> > -
> >   	rval = nvmem_add_cells_from_layout(nvmem);
> >   	if (rval)
> >   		goto err_remove_cells;
> > @@ -2126,6 +2123,19 @@ const char *nvmem_dev_name(struct nvmem_device *nvmem)
> >   }
> >   EXPORT_SYMBOL_GPL(nvmem_dev_name);
> >   
> > +static const struct of_device_id fixed_layout_of_match_table[] = {
> > +	{ .compatible = "fixed-layout", },
> > +	{},
> > +};
> > +MODULE_DEVICE_TABLE(of, fixed_layout_of_match_table);
> > +
> > +static struct nvmem_layout fixed_layout = {
> > +	.name = "NVMEM fixed layout",
> > +	.of_match_table = fixed_layout_of_match_table,
> > +	.add_cells = nvmem_add_cells_from_fixed_layout,
> > +};
> > +module_nvmem_layout_driver(fixed_layout);
> > +
> >   static int __init nvmem_init(void)
> >   {
> >   	return bus_register(&nvmem_bus_type);  
> 
> 

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>


Thanks,
Miquèl
Re: [PATCH] nvmem: fix issue within nvmem_register with fixed-layout.
Posted by Miquel Raynal 1 year, 11 months ago
Hi Catalin,

miquel.raynal@bootlin.com wrote on Tue, 5 Dec 2023 10:05:02 +0100:

> Hi Catalin,
> 
> + GKH
> + Luca (who initially reported this issue)
> 
> catalin.popescu@leica-geosystems.com wrote on Tue, 5 Dec 2023 08:48:27
> +0000:
> 
> > Adding more people.
> > 
> > On 30.11.23 17:29, Catalin Popescu wrote:
> > > fixed-layout is natively supported by NVMEM framework.
> > > Yet, it's not been declared as a supported layout. As a
> > > result, nvmem_register always returns -EPROBE_DEFER if
> > > configuration has no layout and the NVMEM provider DT
> > > uses a fixed layout.
> > >
> > > As a fix, declare fixed-layout as a supported layout
> > > and use add_cells callback to parse the cells. This adds
> > > consistency over layouts parsing as fixed-layout parsing
> > > is handled in the same way than others nvmem layouts.
> 
> I believe this patch (not taken yet) should fix your issue and should be
> queued to fixes.
> 
> Link: https://lore.kernel.org/lkml/20231124193814.360552-1-miquel.raynal@bootlin.com/
> 
> However I like your approach which should probably be taken into
> consideration for the next cycle, as I think it fits Rafal's
> original idea pretty well.

Do you plan on updating this patch at -rc1? I think it would be
interesting to follow your idea.

Thanks,
Miquèl