2023-01-05 14:34:54

by Michael Walle

[permalink] [raw]
Subject: [PATCH] nvmem: core: return -ENOENT if nvmem cell is not found

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: 3cb05fdbaed6 ("nvmem: core: add an index parameter to the cell")
Reported-by: Alexander Stein <[email protected]>
Signed-off-by: Michael Walle <[email protected]>
---

Alexander, could you give this another try? I've changed it slightly,
so it's a better match with how the handling was before.


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 1b61c8bf0de4..cc885b602690 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1343,7 +1343,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);
--
2.30.2


2023-01-05 14:40:57

by Alexander Stein

[permalink] [raw]
Subject: Re: [PATCH] nvmem: core: return -ENOENT if nvmem cell is not found

Am Donnerstag, 5. Januar 2023, 14:59:31 CET schrieb Michael Walle:
> 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: 3cb05fdbaed6 ("nvmem: core: add an index parameter to the cell")
> Reported-by: Alexander Stein <[email protected]>
> Signed-off-by: Michael Walle <[email protected]>
> ---
>
> Alexander, could you give this another try? I've changed it slightly,
> so it's a better match with how the handling was before.
>
>
> 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 1b61c8bf0de4..cc885b602690 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1343,7 +1343,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);

Tested-by: Alexander Stein <[email protected]>



2023-01-05 18:14:01

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH] nvmem: core: return -ENOENT if nvmem cell is not found



On 05/01/2023 13:59, Michael Walle wrote:
> 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: 3cb05fdbaed6 ("nvmem: core: add an index parameter to the cell")
> Reported-by: Alexander Stein <[email protected]>
> Signed-off-by: Michael Walle <[email protected]>
> ---
>

Applied thanks,

--srini
> Alexander, could you give this another try? I've changed it slightly,
> so it's a better match with how the handling was before.
>
>
> 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 1b61c8bf0de4..cc885b602690 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -1343,7 +1343,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);