ipq806x: add thermal sensor driver
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.4 / 019-1-nvmem-core-return-error-for-non-word-aligned-access.patch
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
5
6 nvmem providers have restrictions on register strides, so return error
7 when users attempt to read/write buffers with sizes which are less
8 than word size.
9
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
12 in userspace.
13
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>
17 ---
18 drivers/nvmem/core.c | 6 ++++++
19 1 file changed, 6 insertions(+)
20
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)
25 return 0;
26
27 + if (count < nvmem->word_size)
28 + return -EINVAL;
29 +
30 if (pos + count > nvmem->size)
31 count = nvmem->size - pos;
32
33 @@ -95,6 +98,9 @@ static ssize_t bin_attr_nvmem_write(stru
34 if (pos >= nvmem->size)
35 return 0;
36
37 + if (count < nvmem->word_size)
38 + return -EINVAL;
39 +
40 if (pos + count > nvmem->size)
41 count = nvmem->size - pos;
42