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>

authored by Srinivas Kandagatla and committed by Greg Kroah-Hartman 2f9ba5b2 7326fffb

Changed files
+6
drivers
nvmem
+6
drivers/nvmem/core.c
··· 70 70 if (pos >= nvmem->size) 71 71 return 0; 72 72 73 + if (count < nvmem->word_size) 74 + return -EINVAL; 75 + 73 76 if (pos + count > nvmem->size) 74 77 count = nvmem->size - pos; 75 78 ··· 97 94 /* Stop the user from writing */ 98 95 if (pos >= nvmem->size) 99 96 return 0; 97 + 98 + if (count < nvmem->word_size) 99 + return -EINVAL; 100 100 101 101 if (pos + count > nvmem->size) 102 102 count = nvmem->size - pos;