[v2,09/21] nvmem: core: return -ENOENT if nvmem cell is not found

Message ID 20230307165359.225361-10-miquel.raynal@bootlin.com
State New
Headers
Series nvmem: Layouts support |

Commit Message

Miquel Raynal March 7, 2023, 4:53 p.m. UTC
  From: Michael Walle <michael@walle.cc>

Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
found. Particularly, if of_property_match_string() returned -EINVAL,
that return code was passed as the index to of_parse_phandle(), which
then detected it as invalid and returned NULL. That led to an return
code of -ENOENT.

With the new code, the negative index will lead to an -EINVAL of
of_parse_phandle_with_optional_args() which pass straight to the
caller and break those who expect an -ENOENT.

Fix it by always returning -ENOENT.

Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Michael Walle March 7, 2023, 5:04 p.m. UTC | #1
Am 2023-03-07 17:53, schrieb Miquel Raynal:
> From: Michael Walle <michael@walle.cc>
> 
> Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
> the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
> found. Particularly, if of_property_match_string() returned -EINVAL,
> that return code was passed as the index to of_parse_phandle(), which
> then detected it as invalid and returned NULL. That led to an return
> code of -ENOENT.
> 
> With the new code, the negative index will lead to an -EINVAL of
> of_parse_phandle_with_optional_args() which pass straight to the
> caller and break those who expect an -ENOENT.
> 
> Fix it by always returning -ENOENT.
> 
> Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
> Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> Signed-off-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Misses the Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
tag. But.. this is already applied anyways:
https://lore.kernel.org/r/515d5fed-2083-c1fd-eea5-148d9e1c45bd@linaro.org/

-michael
  
Srinivas Kandagatla March 10, 2023, 9:57 a.m. UTC | #2
On 07/03/2023 16:53, Miquel Raynal wrote:
> From: Michael Walle <michael@walle.cc>
> 
> Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
> the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
> found. Particularly, if of_property_match_string() returned -EINVAL,
> that return code was passed as the index to of_parse_phandle(), which
> then detected it as invalid and returned NULL. That led to an return
> code of -ENOENT.
> 
> With the new code, the negative index will lead to an -EINVAL of
> of_parse_phandle_with_optional_args() which pass straight to the
> caller and break those who expect an -ENOENT.
> 
> Fix it by always returning -ENOENT.
> 
> Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
> Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> Signed-off-by: Michael Walle <michael@walle.cc>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---

Already applied.

--srini
>   drivers/nvmem/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 174ef3574e07..22024b830788 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1231,7 +1231,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
>   						  "#nvmem-cell-cells",
>   						  index, &cell_spec);
>   	if (ret)
> -		return ERR_PTR(ret);
> +		return ERR_PTR(-ENOENT);
>   
>   	if (cell_spec.args_count > 1)
>   		return ERR_PTR(-EINVAL);
  
Miquel Raynal March 10, 2023, 10 a.m. UTC | #3
Hi Srinivas,

srinivas.kandagatla@linaro.org wrote on Fri, 10 Mar 2023 09:57:54 +0000:

> On 07/03/2023 16:53, Miquel Raynal wrote:
> > From: Michael Walle <michael@walle.cc>
> > 
> > Prior to commit 3cb05fdbaed6 ("nvmem: core: add an index parameter to
> > the cell") of_nvmem_cell_get() would return -ENOENT if the cell wasn't
> > found. Particularly, if of_property_match_string() returned -EINVAL,
> > that return code was passed as the index to of_parse_phandle(), which
> > then detected it as invalid and returned NULL. That led to an return
> > code of -ENOENT.
> > 
> > With the new code, the negative index will lead to an -EINVAL of
> > of_parse_phandle_with_optional_args() which pass straight to the
> > caller and break those who expect an -ENOENT.
> > 
> > Fix it by always returning -ENOENT.
> > 
> > Fixes: efff2655ab0f ("nvmem: core: add an index parameter to the cell")
> > Reported-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> > Signed-off-by: Michael Walle <michael@walle.cc>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---  
> 
> Already applied.

Yes, sorry, Michael spotted it as well, I wasn't based on the right
branch. v3 is udpated on this regard.

Thanks,
Miquèl
  

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 174ef3574e07..22024b830788 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1231,7 +1231,7 @@  struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 						  "#nvmem-cell-cells",
 						  index, &cell_spec);
 	if (ret)
-		return ERR_PTR(ret);
+		return ERR_PTR(-ENOENT);
 
 	if (cell_spec.args_count > 1)
 		return ERR_PTR(-EINVAL);