1 From 313a72ff983cc2e00ac4dcb791d40ebf2f9d5718 Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
3 Date: Tue, 17 Nov 2015 09:12:41 +0000
4 Subject: nvmem: core: return error for non word aligned access
6 nvmem providers have restrictions on register strides, so return error
7 when users attempt to read/write buffers with sizes which are less
10 Without this patch the userspace would continue to try as it does not
11 get any error from the nvmem core, resulting in a hang or endless loop
14 Reported-by: Ariel D'Alessandro <ariel@vanguardiasur.com.ar>
15 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 drivers/nvmem/core.c | 6 ++++++
19 1 file changed, 6 insertions(+)
21 --- a/drivers/nvmem/core.c
22 +++ b/drivers/nvmem/core.c
23 @@ -70,6 +70,9 @@ static ssize_t bin_attr_nvmem_read(struc
24 if (pos >= nvmem->size)
27 + if (count < nvmem->word_size)
30 if (pos + count > nvmem->size)
31 count = nvmem->size - pos;
33 @@ -95,6 +98,9 @@ static ssize_t bin_attr_nvmem_write(stru
34 if (pos >= nvmem->size)
37 + if (count < nvmem->word_size)
40 if (pos + count > nvmem->size)
41 count = nvmem->size - pos;