Skip to content

Commit 28b0087

Browse files
Joy Chakrabortygregkh
authored andcommitted
nvmem: rmem: Fix return value of rmem_read()
reg_read() callback registered with nvmem core expects 0 on success and a negative value on error but rmem_read() returns the number of bytes read which is treated as an error at the nvmem core. This does not break when rmem is accessed using sysfs via bin_attr_nvmem_read()/write() but causes an error when accessed from places like nvmem_access_with_keepouts(), etc. Change to return 0 on success and error in case memory_read_from_buffer() returns an error or -EIO if bytes read do not match what was requested. Fixes: 5a3fa75 ("nvmem: Add driver to expose reserved memory as nvmem") Cc: [email protected] Signed-off-by: Joy Chakraborty <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a6a0f04 commit 28b0087

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/nvmem/rmem.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ static int rmem_read(void *context, unsigned int offset,
4646

4747
memunmap(addr);
4848

49-
return count;
49+
if (count < 0)
50+
return count;
51+
52+
return count == bytes ? 0 : -EIO;
5053
}
5154

5255
static int rmem_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)