From: Srinivas Kandagatla Date: Tue, 17 Nov 2015 09:12:41 +0000 (+0000) Subject: UPSTREAM: nvmem: core: return error for non word aligned access X-Git-Tag: firefly_0821_release~1985 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=93f1ffeb1b9b4c66e37f28550ac1ec5c24ee1263;p=firefly-linux-kernel-4.4.55.git UPSTREAM: 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. Change-Id: Iffb76b5a784a79a008f80281ac64449733b855a6 Reported-by: Ariel D'Alessandro Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman Signed-off-by: Finley Xiao (cherry pick from 2f9ba5b2f8420e0e5712080dafc773f7dd47c3df) --- 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;