Skip to contentSkip to conversation

nvmem: core: fix wrong error codes for missing reg_read/reg_write

PATCH New Haotian Zhang 1 participant 1 message Dec 4, 2025 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: core: fix wrong error codes for missing reg_read/reg_write

When nvmem accessors are NULL, returning -EPERM misrepresents the condition as a permission error instead of an unsupported operation.

Return -EOPNOTSUPP when reg_read/reg_write is NULL. Keep -EPERM only for read-only cases.

Fixes 3c91ef69a3e9 ("nvmem: check for NULL reg_read and reg_write before dereferencing")
---
 drivers/nvmem/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvmem/core.c +4 -2
index 597598db88f4..93591de530d3 100644
@@ -232,7 +232,7 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
 	count = round_down(count, nvmem->word_size);
 
 	if (!nvmem->reg_read)
-		return -EPERM;
+		return -EOPNOTSUPP;
 
 	rc = nvmem_reg_read(nvmem, pos, buf, count);
 
@@ -264,7 +264,9 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
 
 	count = round_down(count, nvmem->word_size);
 
-	if (!nvmem->reg_write || nvmem->read_only)
+	if (!nvmem->reg_write)
+		return -EOPNOTSUPP;
+	if (nvmem->read_only)
 		return -EPERM;
 
 	rc = nvmem_reg_write(nvmem, pos, buf, count);
Signature · 1 line
2.50.1.windows.1