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")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/nvmem/core.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 597598db88f4..93591de530d3 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -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);
--
2.50.1.windows.1