nvmem: core: fix wrong error codes for missing reg_read/reg_write
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")
Signed-off-by Haotian Zhang <[email protected]>
--- drivers/nvmem/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvmem/core.c +4 -2
@@ -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