Skip to content

Commit 2f9ba5b

Browse files
Srinivas-Kandagatlagregkh
authored andcommitted
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 <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7326fff commit 2f9ba5b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/nvmem/core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ static ssize_t bin_attr_nvmem_read(struct file *filp, struct kobject *kobj,
7070
if (pos >= nvmem->size)
7171
return 0;
7272

73+
if (count < nvmem->word_size)
74+
return -EINVAL;
75+
7376
if (pos + count > nvmem->size)
7477
count = nvmem->size - pos;
7578

@@ -95,6 +98,9 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
9598
if (pos >= nvmem->size)
9699
return 0;
97100

101+
if (count < nvmem->word_size)
102+
return -EINVAL;
103+
98104
if (pos + count > nvmem->size)
99105
count = nvmem->size - pos;
100106

0 commit comments

Comments
 (0)