* [PATCH v3] nvmem: rmem: Fix return value of rmem_read()
@ 2024-06-07 16:05 Joy Chakraborty
2024-06-07 16:47 ` Dan Carpenter
2024-06-11 9:30 ` Srinivas Kandagatla
0 siblings, 2 replies; 3+ messages in thread
From: Joy Chakraborty @ 2024-06-07 16:05 UTC (permalink / raw)
To: Srinivas Kandagatla, Greg Kroah-Hartman, Rob Herring,
Nicolas Saenz Julienne, Dan Carpenter
Cc: linux-kernel, manugautam, Joy Chakraborty, stable
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")
Cc: stable@vger.kernel.org
Signed-off-by: Joy Chakraborty <joychakr@google.com>
---
drivers/nvmem/rmem.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/rmem.c b/drivers/nvmem/rmem.c
index 752d0bf4445e..7f907c5a445e 100644
--- a/drivers/nvmem/rmem.c
+++ b/drivers/nvmem/rmem.c
@@ -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)
--
2.45.2.505.gda0bf45e8d-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] nvmem: rmem: Fix return value of rmem_read()
2024-06-07 16:05 [PATCH v3] nvmem: rmem: Fix return value of rmem_read() Joy Chakraborty
@ 2024-06-07 16:47 ` Dan Carpenter
2024-06-11 9:30 ` Srinivas Kandagatla
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-06-07 16:47 UTC (permalink / raw)
To: Joy Chakraborty
Cc: Srinivas Kandagatla, Greg Kroah-Hartman, Rob Herring,
Nicolas Saenz Julienne, linux-kernel, manugautam, stable
On Fri, Jun 07, 2024 at 04:05:10PM +0000, Joy Chakraborty wrote:
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Joy Chakraborty <joychakr@google.com>
> ---
Thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
You mentioned some other functions that had similar bugs. Could you
fix those as well.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] nvmem: rmem: Fix return value of rmem_read()
2024-06-07 16:05 [PATCH v3] nvmem: rmem: Fix return value of rmem_read() Joy Chakraborty
2024-06-07 16:47 ` Dan Carpenter
@ 2024-06-11 9:30 ` Srinivas Kandagatla
1 sibling, 0 replies; 3+ messages in thread
From: Srinivas Kandagatla @ 2024-06-11 9:30 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rob Herring, Nicolas Saenz Julienne,
Dan Carpenter, Joy Chakraborty
Cc: linux-kernel, manugautam, stable
On Fri, 07 Jun 2024 16:05:10 +0000, Joy Chakraborty wrote:
> 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,
--
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-06-11 9:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-07 16:05 [PATCH v3] nvmem: rmem: Fix return value of rmem_read() Joy Chakraborty
2024-06-07 16:47 ` Dan Carpenter
2024-06-11 9:30 ` Srinivas Kandagatla
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox