diff options
author | Srinivas Kandagatla <srinivas.kandagatla@linaro.org> | 2015-11-17 09:12:41 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-02-07 23:07:21 -0800 |
commit | 313a72ff983cc2e00ac4dcb791d40ebf2f9d5718 (patch) | |
tree | e4031aac8cd831d5e737acc4f52ca56f73ddabdb | |
parent | 4c7e4fe3776693ee4554ca1b3a2c728c1f8f361a (diff) | |
download | linux-stable-313a72ff983cc2e00ac4dcb791d40ebf2f9d5718.tar.gz linux-stable-313a72ff983cc2e00ac4dcb791d40ebf2f9d5718.tar.bz2 linux-stable-313a72ff983cc2e00ac4dcb791d40ebf2f9d5718.zip |
nvmem: core: return error for non word aligned access
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>
-rw-r--r-- | drivers/nvmem/core.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 6fd4e5a5ef4a..9d11d9837312 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -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; @@ -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; |