Skip to contentSkip to conversation

nvmem: core: return -ENOENT if nvmem cell is not found

PATCH Superseded Michael Walle 3 participants 3 messages Jan 5, 2023 NVMEM framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")

---

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(-)
drivers/nvmem/core.c +1 -1
index 1b61c8bf0de4..cc885b602690 100644
@@ -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);
Signature · 1 line
2.30.2
Tested-by on v1 1/1
#1 lore raw

Am Donnerstag, 5. Januar 2023, 14:59:31 CET schrieb Michael Walle:

Quoted 30 lines

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

---

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(-)
drivers/nvmem/core.c +0 -0
index 1b61c8bf0de4..cc885b602690 100644

drivers/nvmem/core.c struct nvmem_cell *of_nvmem_cell_get(struct · line 1344

Quoted 2 lines
drivers/nvmem/core.c +0 -0
@@ -1343,7 +1343,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct
 device_node *np, const char *id) "#nvmem-cell-cells",
 						  index, 

&cell_spec);

drivers/nvmem/core.c struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) · line 1349

Quoted 6 lines
drivers/nvmem/core.c +1 -1
 	if (ret)
-		return ERR_PTR(ret);
+		return ERR_PTR(-ENOENT);
 
 	if (cell_spec.args_count > 1)
 		return ERR_PTR(-EINVAL);
#2 lore raw
In reply to Michael Walle
Quoted 11 lines · 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.

Quoted 7 lines

Fix it by always returning -ENOENT.

Fixes 3cb05fdbaed6 ("nvmem: core: add an index parameter to the cell")

---

Applied thanks,

--srini

Quoted 20 lines

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(-)
drivers/nvmem/core.c +1 -1
index 1b61c8bf0de4..cc885b602690 100644
@@ -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);