Skip to contentSkip to conversation

nvmem: rmem: Fix return value of rmem_read()

PATCH Applied Joy Chakraborty 3 participants 3 messages Jun 7, 2024 – Jun 11, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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 5a3fa75a4d9c ("nvmem: Add driver to expose reserved memory as nvmem")
---
 drivers/nvmem/rmem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvmem/rmem.c +4 -1
index 752d0bf4445e..7f907c5a445e 100644
@@ -46,7 +46,10 @@ static int rmem_read(void *context, unsigned int offset,
 
 	memunmap(addr);
 
-	return count;
+	if (count < 0)
+		return count;
+
+	return count == bytes ? 0 : -EIO;
 }
 
 static int rmem_probe(struct platform_device *pdev)
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Joy Chakraborty

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.

Quoted 8 lines

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 5a3fa75a4d9c ("nvmem: Add driver to expose reserved memory as nvmem")

---

Thanks!

You mentioned some other functions that had similar bugs. Could you fix those as well.

regards,
dan carpenter

#2 lore raw
In reply to Joy Chakraborty
Quoted 9 lines · Joy Chakraborty

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.

[...]

Applied, thanks!

[1/1] nvmem: rmem: Fix return value of rmem_read()

      commit: 139eb4bb33a2857fe439c02a201a85af52ce6186

Best regards,

Signature · 1 line
Srinivas Kandagatla <[email protected]>