1 From 7a0a6d0a7c805f9380381f4deedffdf87b93f408 Mon Sep 17 00:00:00 2001
2 From: Joy Chakraborty <joychakr@google.com>
3 Date: Fri, 28 Jun 2024 12:37:02 +0100
4 Subject: [PATCH] nvmem: meson-efuse: Fix return value of nvmem callbacks
6 Read/write callbacks registered with nvmem core expect 0 to be returned
7 on success and a negative value to be returned on failure.
9 meson_efuse_read() and meson_efuse_write() call into
10 meson_sm_call_read() and meson_sm_call_write() respectively which return
11 the number of bytes read or written on success as per their api
14 Fix to return error if meson_sm_call_read()/meson_sm_call_write()
15 returns an error else return 0.
17 Fixes: a29a63bdaf6f ("nvmem: meson-efuse: simplify read callback")
18 Cc: stable@vger.kernel.org
19 Signed-off-by: Joy Chakraborty <joychakr@google.com>
20 Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
21 Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
22 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
23 Link: https://lore.kernel.org/r/20240628113704.13742-3-srinivas.kandagatla@linaro.org
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 drivers/nvmem/meson-efuse.c | 14 ++++++++++----
27 1 file changed, 10 insertions(+), 4 deletions(-)
29 --- a/drivers/nvmem/meson-efuse.c
30 +++ b/drivers/nvmem/meson-efuse.c
31 @@ -18,18 +18,24 @@ static int meson_efuse_read(void *contex
32 void *val, size_t bytes)
34 struct meson_sm_firmware *fw = context;
37 - return meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
39 + ret = meson_sm_call_read(fw, (u8 *)val, bytes, SM_EFUSE_READ, offset,
42 + return ret < 0 ? ret : 0;
45 static int meson_efuse_write(void *context, unsigned int offset,
46 void *val, size_t bytes)
48 struct meson_sm_firmware *fw = context;
51 + ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
54 - return meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
56 + return ret < 0 ? ret : 0;
59 static const struct of_device_id meson_efuse_match[] = {