Skip to content

Commit

Permalink
nvmem: core: return error for non word aligned access
Browse files Browse the repository at this point in the history
nvmem providers have restrictions on register strides, so return error
when users attempt to read/write buffers with sizes which are less
than word size.

Without this patch the userspace would continue to try as it does not
get any error from the nvmem core, resulting in a hang or endless loop
in userspace.

Reported-by: Ariel D'Alessandro <ariel@vanguardiasur.com.ar>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Srinivas Kandagatla authored and Greg Kroah-Hartman committed Feb 8, 2016
1 parent 7326fff commit 2f9ba5b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/nvmem/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
if (pos >= nvmem->size)
return 0;

if (count < nvmem->word_size)
return -EINVAL;

if (pos + count > nvmem->size)
count = nvmem->size - pos;

Expand All @@ -95,6 +98,9 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
if (pos >= nvmem->size)
return 0;

if (count < nvmem->word_size)
return -EINVAL;

if (pos + count > nvmem->size)
count = nvmem->size - pos;

Expand Down

0 comments on commit 2f9ba5b

Please sign in to comment.